今天倒騰linux根文件系統的時候發現 cp -r?/dev /dev_bak 時,竟然會 將磁盤設備中的數據進行一次拷貝,而不是僅僅建立設備文件。
于是到網上搜了一把,收獲不小。
http://www.loveunix.net/html/200407/33920.html
這里有人問同樣的問題,某人用英文作答:
-r Copies file hierarchies under the file or directory specified by the SourceFile or SourceDirectory parameter (recursive copy).?The -r flag processes special files in the same manner as regular files.?
-R Copies file hierarchies under the regular files and directories from the directory specified by the SourceFile or SourceDirectory parameter to the directory specified by the TargetDirectory parameter.?Special file types, such as first-in, first-out (FIFO) files and block and character device files, are re-created instead of copied.Symbolic links are followed unless the -h flag is specified. (The -R flag is preferred to the -r flag.)
-R Copies file hierarchies under the regular files and directories from the directory specified by the SourceFile or SourceDirectory parameter to the directory specified by the TargetDirectory parameter.?Special file types, such as first-in, first-out (FIFO) files and block and character device files, are re-created instead of copied.Symbolic links are followed unless the -h flag is specified. (The -R flag is preferred to the -r flag.)
? 這個回答已經是很明白了,
? ?cp -r 會把所有source當作普通文件(regular文件);
?而cp -R 對特殊文件(管道文件,塊設備文件,字符設備文件)會進行創建操作,而不是拷貝。
其實,以前我也看到過關于cp -r 和cp -R 的區別說明,只不過當時我沒有遇到具體的情景,所以沒有在意。