[Tip] Subtlety of the UNIX command cp

Little tip on the popular UNIX comand cp.
When you want to copy a directory you have to specify the -R option, and there is a little trick with this option.

If you put the / at the end of the directory you want to copy, it’s the content of the file which will be copied, and not the directory itself !

Example : I have a directory ~/Desktop/TEST/ in which there are 3 files, bla1, bla2, bla3.

If I do

cp -R ~/Desktop/TEST/ ~/

The files bla1, bla2, bla3 will be copied in my home directory, but if I do

cp -R ~/Desktop/TEST ~/

The directory TEST will be copied to my home.

So, little subtlety to know, because it’s a bit frustrating when we do the mistake, but well, there is the man ;)

PS : Yes, I make this post because I got owned yesterday :)

One thought on “[Tip] Subtlety of the UNIX command cp

  1. Me suis pas encore fait avoir… Merci de prévenir. Tiens ça a changé de look ici…
    Question bête, ça sert à quoi tout les liens/boutons “Ajouter truc” en dessous du post ? T’utilises tout ça ou ça vient tout seul avec wordpress ?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>