The difference between -r and -R

Most POSIX commands that have recursive directory traversal option (ls, chmod, chgrp, chmod, cp, rm) have -R for that.

rm also has -r because that's what it was initially, long before POSIX.

Now, the behaviour varies when symlinks are found in walking down the tree. POSIX tried to make things consistent by adding the -L/-H/P options to give the user a chance to decide what to do with symlinks leaving the default when none is provided unspecified.

POSIX grep has no -r or -R.

GNU grep initially had neither. -r was added in 1998. That was following symlinks.

-R was added as a synonym in 2001 for consistency with the other utilities. That was still following symlinks.

In 2012 (grep 2.12), -r was changed so it no longer followed symlinks, possibly because -L, -H were already used for something else.

BSDs grep were based on GNU grep for a long time. Some of them have rewritten their own and kept more or less compatibility with GNU grep. Apple OS/X addressed the symlink issue differently. -r and -R are the same and don't follow symlinks. There's a -S option however that acts like chmod/cp/find's -L option to follow symlinks.


None whatsoever. It simply depends on what the developers chose. It is often because both -r and -R are valid options. In the programs you quoted, for example:

  • recent versions of GNU grep:

    -r, --recursive
          Read all files  under  each  directory,  recursively,  following
          symbolic  links  only  if they are on the command line.  This is
          equivalent to the -d recurse option.
    
    -R, --dereference-recursive
          Read all files under each directory,  recursively.   Follow  all
          symbolic links, unlike -r.
    
  • chmod has no -r option so, presumably, the devs prefer -R. However, of course, -r is a valid permissions string (as pointed out by @Arkadiusz Drabczykso) so it can't really be used there.


Mostly, it comes down to a developer personal preference. Sometimes, however, an uppercase option is chosen if a preferred lowercase option is taken for something else that developers believe is more important than, for example, operating recursively. In case of chmod -r is a valid mode. For example:

$ ll FILE
-rw-r--r-- 1 ja ja 0 Sep  9 16:42 FILE
$ chmod -r FILE
$ ll FILE
--w------- 1 ja ja 0 Sep  9 16:42 FILE