Cp command copies a file, without distinction source directory with slash

When I was a Linux super silly white when you need to copy a large data set, and then copied back to the source folder with a forward slash, and then found the whole thing is actually a copy of the folder, rather than folder itself. But added little thing, I re-build a folder, move into these things on the line. Later, after I remember this trick, I found sometimes actually not the case. So, doing experiments, simply clear out.


Two folders, each of which reads as follows:

image


After using the command cp -R dir_src / dir_target, the following results:

image


Over again, after use cp -R dir_src dir_target, the following results:

image


So I remember this difference with or without forward slash.

Later, I deliberately use this method slash copy, when actually planted.


Two each folder as follows:

image


Use the command with a slash cp -R copytest_src / copytest_target, the following results:

image


It seems different Linux distributions on the cp command with execution without the slash is not the same, the first example is FreeBSD, and the second is CentOS7.


In short, the future do not pick up lazy, and want to copy the contents of the directory rather than the directory itself, use slash and asterisk "cp -R src / * target"; want to copy the directory itself, it is what is not with "cp -R src target "on the line.

Guess you like

Origin www.cnblogs.com/awpatp/p/11125671.html