How to keep the existing file attributes (owner, timestamp, etc) when copying files or directories
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 |
Related posts:
- Newbie: how to edit a file from the command line Could there be any more basic question? We all know there are no stupid questions,...
- Setup WordPress or WPMU to make an atomic version switch — AND allow you to revert I have a new WordPress MU (WPMU) install and I am ready for my first...
- How to rename a file or directory There is no rename function in Ubuntu Linux. Instead, you simply move the file, giving...
Comments on this entry are closed.