So I was going to back up my home folder by copying it to an external drive as follows:

sudo cp -r /home/my_home /media/backup/my_home

With the result that all folders on the external drives are now owned by root:root. How can I have cp keep the ownership and permissions from the original?


Use the -p flag.

-p     same as --preserve=mode,ownership,timestamps

       preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all

Note that for the permissions to be correctly replicated, the destination file system should be the same as the source file system. In other words, your external drive should be formatted as ext4 if, as is usually the case, your home folder is stored on a partition of that type.


Use sudo cp -a /home/my_home /media/backup/my_home, it will recurse into subdirs and preserve all file attributes.


You can use the -p flag:
cp -rp /home/my_home /media/backup/my_home
or use rsync command line:
rsync -aux /home/my_home /media/backup/my_home

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.