4

What does -ar flag mean here:

cp -ar ../foo/bar/. qux/quux/

I'm quite new to command line languages and trying my best to learn it.

Not sure of the -ar flag only. -r is recursive right, then can you just add -a and it becomes -ar? Does -a mean all?

2 Answers 2

7

Generally, multiple single letter flags can be combined into a single argument. In this case:

cp -ar ../foo/bar/. qux/quux/

is equivalent to:

cp -a -r ../foo/bar/. qux/quux/

If you look in the manual, it will tell you that -a is "same as -dR --preserve=all". You can look all of those up if you want, but the short version is that the -a flag causes the new files to have the same permissions, owner, timestamp, etc. as the original files. (Normally, they would be owned by the user performing the 'cp' with permissions defined by your shell configuration, and a current timestamp.)

3
  • Does -r and -R has any difference? Jun 3, 2015 at 16:53
  • 2
    @Nomadme see unix.stackexchange.com/questions/18712/… - tl;dr: you should only use -R, not -r, because -r has non-portable (and often undesired) semantics for symbolic links and special files. But they're not different on Linux.
    – Random832
    Jun 3, 2015 at 17:39
  • @Random832, thank you for explaining that. I have been always using -r and will use -R now on. Jun 5, 2015 at 13:14
3

It's two independent options - -a and -r. It is common practise for unix-like commands to use this "compact" options scheme if the options are boolean. Check man cp for what -a means.

1
  • Awesome, thanks for the direction. I completely forgot to use the "man". lol. I told you I'm newbie :) Jun 3, 2015 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .