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

C

CrazedNerd

Guest
It says "archive" on the man page, but it seems to just do the same thing as cp without options.
 


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:

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

Staff online

Members online


Top