What the heck is the "-a" option for cp?

CrazedNerd

Active Member
Joined
Mar 31, 2021
Messages
364
Reaction score
166
Credits
3,253
It says "archive" on the man page, but it seems to just do the same thing as cp without options.
 


KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
6,190
Reaction score
5,562
Credits
49,899
If I'm reading correctly, it's preserving links (like softlinks) and doing so recursively - meaning if you're in directory A and inside A exist directories A1, A2, and A3, it will also copy those directories to the specified location.

Hmm... I decided to check my conclusion and discovered this, which may help:

 

needafatima

New Member
Joined
May 19, 2022
Messages
3
Reaction score
5
Credits
37
While copying a directory using cp command we generally use -r or -R option, but in place of -r option we can use ‘-a’ which will archive the files and directory during copy, example is shown below,

Screenshot 2022-05-19 193732.png

The cp -a command copies the file/directory with the same permission settings and metadata as the original. It preserve as much as possible of the structure and attributes of the original files in the copy: same directory tree, same file types, same contents, same metadata (times, permissions, extended attributes, etc.).

As in the example shown above, we find that the file characteristics (timestamps specifically) of Doc1 are different from that of Documents as it was copied using -r option but the characteristics (timestamps) of files in Doc2 are same as that of Documents. As Doc2 is copied using -a option, it tries to preserve as many attributes as possible.
 
Last edited:
OP
CrazedNerd

CrazedNerd

Active Member
Joined
Mar 31, 2021
Messages
364
Reaction score
166
Credits
3,253
As in the example shown above, we find that the file characteristics (timestamps specifically) of Doc1 are different from that of Documents as it was copied using -r option but the characteristics (timestamps) of files in Doc2 are same as that of Documents. As Doc2 is copied using -a option, it tries to preserve as many attributes as possible.

that's the impression i got from my searches, however, there's not much mention of which metadata isn't preserved with the normal cp. I would think that "archive", based on the word alone, would do the same thing as "- -backup" which basically just allows to create slightly modified copies of copies within another directory.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Staff online

Members online


Top