Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 9 down vote accepted

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.

share|improve this answer

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

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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