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?

Chris Davies
  • 116,213
  • 16
  • 160
  • 287

2 Answers2

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.)

Drew
  • 396
  • Does -r and -R has any difference? – Ganbayar Gansukh Jun 03 '15 at 16:53
  • 2
    @Nomadme see http://unix.stackexchange.com/questions/18712/difference-between-cp-r-and-cp-r-copy-command - 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 03 '15 at 17:39
  • @Random832, thank you for explaining that. I have been always using -r and will use -R now on. – Ganbayar Gansukh Jun 05 '15 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.

jficz
  • 237