Difference between cp -r and cp -R (copy command)
While -R
is posix well-defined, -r
is not portable!
On Linux, in the GNU and BusyBox implementations of cp
, -r
and -R
are equivalent.
On the other side, as you can read in the POSIX manual page of cp
, -r
behavior is implementation-defined.
* 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.
Lowercase -r
was an older option, introduced in 4.1BSD, which would simply copy all non-directories as files. That is, if it encountered a device or FIFO, it would open it, read the contents, and create a file at the destination with the contents.
Uppercase -R
was a standardized option (introduced to BSD in 4.4BSD, though earlier versions had it as a synonym to -r
) which would, on encountering a device, FIFO, or other special file, make an equivalent special file at the destination.
Many implementations do still maintain this distinction, but some (including the GNU version typical to Linux) only provide the -R
semantics, with -r
as a synonym.
The difference is that one uses a lowercase "R" and the other uses a capital "R". Beyond that, no difference. Same thing if you use the --recursive
long option.