Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

2 Answers 2

up vote 4 down vote accepted

Use the -p flag.

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

--preserve[=ATTR_LIST]
       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

Your Answer

 
discard

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.