Tuesday, May 7, 2024
36
rated 0 times [  36] [ 0]  / answers: 1 / hits: 67355  / 3 Years ago, fri, november 19, 2021, 4:48:07

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?


More From » command-line

 Answers
7

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.


[#36706] Saturday, November 20, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
memorrappin

Total Points: 325
Total Questions: 122
Total Answers: 100

Location: Armenia
Member since Sat, Sep 12, 2020
4 Years ago
;