Skip to main content

Copying files - preserving attributes

One way to do this is:

Supposedly, the following will work to copy a file (or group of files) from a directory and preserve the attributes (ownership and permissions).

$ cd /path/to/source/dir
$ find . | cpio -pdumv /path/to/destination/dir

The cpio command is a copy command designed to copy files into and out of a cpio or tar archive, automatically preserving permissions, times, and ownership of files and subdirectories.

An alternative is to use the "-p" option on the cp command.

See "cp --help" or "man cp" for further details.

Of course, don't forget to add the "-r" on as well, so it copies all files / directories recursively. So you'd use something like:

cp -rp /home/timbruce/data/ /media/backupdrive/timsdata/