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

CrazedNerd

Gold Member
Gold Supporter
Joined
Mar 31, 2021
Messages
521
Reaction score
213
Credits
4,457
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,440
Reaction score
5,711
Credits
51,825
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

Gold Member
Gold Supporter
Joined
Mar 31, 2021
Messages
521
Reaction score
213
Credits
4,457
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!

Linux.org Hosting Donations
Consider making a donation

Members online


Top