Quick viewing(Text Mode)

Linux - Difference Between Cp -R and Cp -A - Unix & Linux Stack Exchange

Linux - Difference Between Cp -R and Cp -A - Unix & Linux Stack Exchange

linux - Difference between cp -r and cp -a - & Stack Exchange http://unix.stackexchange.com/questions/44967/difference-between-cp-...

sign up log in 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.

Difference between cp -r and cp -a

Looking for the difference between cp -r and cp -a? What does recursive mean in terms of copying files from a folder?

/ linux / cp / recursive

edited Aug 8 '12 0:59 asked Aug 7 '12 at 21:36 Gilles Randy 239k 29 356 676 24 1 2

5 I'd recommend you use man pages. – tripledes Aug 7 '12 at 22:03

1 some people are looking for a better explanation to the man pages because it is not always what the description meant. I have had to many times and /experiment to figure out what is really going on with a particular command. 's can confuse me any day. – Joe Aug 7 '12 at 22:41

1 I can understand your frustration, but imo, times best way to learn is to test and experiment. – tripledes Aug 8 '12 at 1:09

2 Answers

Recursive means that cp copies the contents of directories, and if a has subdirectories they are copied (recursively) too. Without -R , the cp command skips directories. -r is identical with -R on Linux, it differs in some edge cases on some other unix variants.

By default, cp creates a new has the same content as the old file, and the same permissions but restricted by the ; the is dated from the of the copy, and belongs to the user doing the copy. With the -p option, the copy has the same modification time, the same access time, and the same permissions as the original. It also has the same owner and group as the original, if the user doing the copy has the permission to create such files.

The -a option means -R and -p , plus a few other preservation options. It attempts to a copy that's as close to the original as possible: same directory , same file types, same contents, same metadata (times, permissions, extended attributes, etc.).

answered Aug 8 '12 at 0:59 Gilles 239k 29 356 676

1 Basically, unless you want something special, you never need -r because -a (for a rchive) is always the safest and probably what you expected to happen. – ams Aug 8 '12 at 9:20

@ams , that's a good summary. The only common reason to use -r is because you're on some unix variant other than Linux that doesn't have -a , and generally you'd use cp -rp . Or -a . – Gilles Aug 8 '12 at 9:51

The -r or -R for recursive means that it will copy all of the files including the files inside of sub folders.

The -a option as listed is the same as -dR which means it will preserve links as well as copy the contents of sub directories. What it means by preserving links is that it will not fallow links as it is recursively copying.

answered Aug 7 '12 at 21:47 Joe 535 2 10

1 von 1 14.01.2015 09:10