Running cp -r ~/.ipython ~/some/path/.ipython a second time creates ~/some/path/.ipython/.ipython. How to prevent that?

2

I am using a script to copy directories to a specified location. When I run cp -r ~/.ipython ~/some/path/.ipython the .ipython dir is copied as expected to the specified location. But when I run this command again ~/some/path/.ipython/.ipython is created.

I understand that this is recursive, but what command copies a dir while for subsequent calls of that command prevent a dir is recursively created inside that same dir?

Bentley4

Posted 2013-05-22T18:18:04.200

Reputation: 1 588

Answers

1

Yes, as you've noticed, nothing prevent the cp command to create a new .ipython dir inside every other .ipython dir.

If you are using it in a script which you run repeatedly, the best approach to avoid the problem is not to use cp but rsync:

rsync -vua ~/.ipython/ ~/some/path/.ipython/

NB, the trailing / at the end of path is significant for rsync. If you are trying it out, don't forget to add that.

EDIT: Kruug's answer should be working as well, but rsync will yield better performance, especially when you are doing it repeatedly.

xpt

Posted 2013-05-22T18:18:04.200

Reputation: 5 548

2

cp -r ~/.ipython/ ~/some/path/.ipython

add the slash, it copies the contents of the directory

Rich Homolka

Posted 2013-05-22T18:18:04.200

Reputation: 27 121

2Could you also do cp -r ~/.ipython ~/some/path/? – Kruug – 2013-05-22T18:47:46.630

Could you make a separate answer of this Kruug? – Bentley4 – 2013-05-22T19:15:39.833

@Rich Homolka : Running that command repeatedly still creates a new .ipython dir inside every other .ipython dir. – Bentley4 – 2013-05-22T19:19:28.433

why are you running the command repeatedly? – MattDMo – 2013-05-22T19:23:29.567

@MattDMo Because I'm using it in a script which I run repeatedly. – Bentley4 – 2013-05-22T19:24:26.457

I guess the question is - what are you trying to accomplish? – MattDMo – 2013-05-22T19:25:10.263

I know there is an other way to get what I want, but it would just be a lot of work. Kruug's answer worked so the problem is solved. – Bentley4 – 2013-05-22T19:27:14.313