Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

cp- r is meant to copy files recursively, and cp -R for copying directories recursively. But I've checked, and both appear to copy both files and directories, the same thing. So, what's the difference actually?

share|improve this question
2  
Every mention of these options in the Linux manuals says that they're synonyms. (They're not on some other unix variants.) –  Gilles Aug 14 '11 at 17:24
add comment

3 Answers

up vote 39 down vote accepted

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.
share|improve this answer
1  
One of the differences would be that, in OSX for example, -r will copy the real files pointed by symbolic links while -R will copy the symbolic link which is what it is intended most of the times. –  nacho4d Apr 15 '13 at 4:35
add comment

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.

share|improve this answer
4  
From the man page: -R, -r, --recursive - copy directories recursively –  Dave Jennings Aug 14 '11 at 8:29
2  
@DaveJennings: Just because they are equivolent on one platform doesn't mean they are on all. On some implementations of cp there actually is a distinction. See Random832's answer. @Ignacio you should include a qualifier in this answer that says "if your cp is the modern GNU implementation" or something like that. –  Caleb Aug 15 '11 at 12:30
    
@Caleb: The question is tagged "linux". What else would it be? –  Ignacio Vazquez-Abrams Aug 15 '11 at 20:06
1  
-R and -r give different behavior on some of the systems I use (OS X, FreeBSD, BusyBox coreutils; not sure which ones at the moment). I decided long ago it was prudent to always use -R only, and in fact some of the man pages on the systems just mentioned also recommend that. –  dubiousjim Nov 15 '12 at 14:17
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.