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

CrazedNerd

Well-Known Member
Joined
Mar 31, 2021
Messages
1,144
Reaction score
523
Credits
9,864
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
8,545
Reaction score
7,302
Credits
69,492
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

Well-Known Member
Joined
Mar 31, 2021
Messages
1,144
Reaction score
523
Credits
9,864
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.
 
MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit: https://www.malibal.com

Staff online

Members online


Latest posts

Top