Skip to content
Advertisement

Difference between *.* and * when used with the cp command and the -R parameter [closed]

I just want to find out what is the difference between

cp -R $rootpath/vgcore/core/src/geom/*.* $destpath/geom_src

,

cp -R $rootpath/vgcore/core/src/geom/* $destpath/geom_src

,

cp -R $rootpath/vgcore/core/src/geom $destpath/geom_src

and

cp -R $rootpath/vgcore/core/src/geom/ $destpath/geom_src

Let’s say we have one subdir in geom, say alg with files in it

  1. In the case of one, would only all the files be copied from geom and alg and put into geom_src? So the dir structure of the source will be ignored?

  2. all the files from geom and all the files from alg + alg itself will be copied over retaining the subdir structure?

  3. sames as 2?

  4. sames as 2 & 3?

Sorry, don’t have a test Linux machine handy to test this myself.

Thanks.

Advertisement

Answer

cp -R $rootpath/vgcore/core/src/geom/. $destpath/geom_src

Every directory entry (files AND sub directories) with a dot in their name, found in …/src/geom, will be copied to …/geom_src

Note that hidden entries (entries whose name begins with a dot) are not copied because they are not seen.

cp -R $rootpath/vgcore/core/src/geom/* $destpath/geom_src

This command is the same as above, but more wide – any file (or “directory entry”) will be copied, not only those containing a dot in the name.

cp -R $rootpath/vgcore/core/src/geom $destpath/geom_src

cp -R $rootpath/vgcore/core/src/geom/ $destpath/geom_src

Are equivalent, and different from before. They copy a single object (directory entry) to the destination; single, because no wildcard has been specified. Taking your specific example, these last two commands will copy everything inside …/geom/, more or less same as before, but they will copy once item more, the directory “geom” itself! And all the files that were inside /geom/ will still go under the newly created “geom” in the destination (assuming that it was not yet existing).

If you asked this, then maybe you come from dos or windows. Under dos/winslow, there is no expansion before a command is executed – it is the command itself that interprets the wild cards. Under unix instead, the arguments are expanded beforehand: if you happen to have 200 items in …/src/geom/, the invoked program (cp for example) will receive 200 parameters.

Another dos/unix difference is that dot (* vs .) you mention. DOS used file names made by 2 parts separated by a (sometimes invisible) dot. Unix does not, a dot has no particular meaning in a file name, apart from the fact that a name starting with a dot is normally not “seen” (and hence considered) by the shell.

Advertisement