When copying files and especially directories, sometimes you want to keep the existing file attributes. For example, you may likely want to keep the same owner, group, timestamp, etc.

You can keep the attributes by using the preserve argument. preserve=all will keep everything:


sudo cp -r --preserve=all original_directory_name copied_directory_name

You can use the -p version of preserve to keep the default attributes. On my Ubuntu Hardy server, the default attributes are mode, ownership, timestamps:


sudo cp -r -p original_directory_name copied_directory_name

If you want to keep a different subset of attributes, you can specify in comma separated list a list with –preserve=[ATTR_LIST].


sudo cp -r --preserve=mode,ownership,timestamps original_directory_name copied_directory_name

Note that this last example is the same as -p, since I listed the default attributes. On my system, the available attributes are mode, ownership, timestamps, context, links, all.

See the help page on your system for available attributes:


cp --help | less

LEAVE A REPLY

Please enter your comment!
Please enter your name here