cp -r用于递归复制文件,以及cp -R递归复制目录。但我已经检查过,两者似乎都复制了文件和目录,同样的事情。那么,实际上有什么区别呢?
and*_*coz 92
虽然-Rposix 定义明确,但-r不可移植!
在 Linux 上,在 GNU 和 BusyBox 实现中cp,-r和-R是等价的。
另一方面,正如您在POSIX手册页中所读到的cp,-r行为是实现定义的。
Run Code Online (Sandbox Code Playgroud)* If neither the -R nor -r options were specified, cp shall take actions based on the type and contents of the file referenced by the symbolic link, and not by the symbolic link itself. * If the -R option was specified: * If none of the options -H, -L, nor -P were specified, it is unspecified which of -H, -L, or -P will be used as a default. * If the -H option was specified, cp shall take actions based on the type and contents of the file referenced by any symbolic link specified as a source_file operand. * If the -L option was specified, cp shall take actions based on the type and contents of the file referenced by any symbolic link specified as a source_file operand or any symbolic links encoun- tered during traversal of a file hierarchy. * If the -P option was specified, cp shall copy any symbolic link specified as a source_file operand and any symbolic links encoun- tered during traversal of a file hierarchy, and shall not follow any symbolic links. * If the -r option was specified, the behavior is implementation- defined.
Ran*_*832 22
小写-r是一个较旧的选项,在 4.1BSD 中引入,它会简单地将所有非目录复制为文件。也就是说,如果它遇到一个设备或 FIFO,它会打开它,读取内容,并在目的地创建一个包含内容的文件。
大写-R是一个标准化选项(在 4.4BSD 中引入 BSD,尽管早期版本将它作为 的同义词-r),当遇到设备、FIFO 或其他特殊文件时,它会在目的地生成一个等效的特殊文件。
许多实现仍然保持这种区别,但有些(包括 Linux 典型的 GNU 版本)只提供-R语义,-r作为同义词。
Ign*_*ams 18
区别在于一个使用小写的“R”,另一个使用大写的“R”。除此之外,没有区别。如果你使用--recursivelong 选项,同样的事情。