Some commands use a lower case r for their recursive flag while others use a capital letter R.

cp -r foo/ bar/

chmod -R 777 foobar/

Is there a reason for this?


cp actually accepts both.

From cp --help:

  -R, -r, --recursive          copy directories recursively

For consistency, most shell commands use -R as a recursive flag, probably because they imitate the behavior of ls.

From ls --help:

  -r, --reverse              reverse order while sorting
  -R, --recursive            list subdirectories recursively
  • 2
    Also, chmod -r is already used to mean something other than recursive! Jun 19 '12 at 18:24

I'm not sure that there's any specific reason to the inconsistancy other than that programmers can choose to use whatever flags they want.

I don't think there's any form of standard for that so it's hard to expect everyone to follow suit.

  • 8
    The reason would likely be historical. In the larger Unix world which dates all the way back to the 70s, the recursive switches weren't always there, and some commands already had made use of -r as a switch. Because commands are often used within scripts, there's tremendous inertia associated with backwards compatibility, so these things basically never change - you can add options to a program, but woe be the developer who tries to change long-established functionality.
    – Stephanie
    Jun 19 '12 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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