Psa*_*nia 478 permissions cp
所以我打算通过将它复制到外部驱动器来备份我的主文件夹,如下所示:
sudo cp -r /home/my_home /media/backup/my_home
Run Code Online (Sandbox Code Playgroud)
结果,外部驱动器上的所有文件夹现在都归root:root. 我怎样才能cp保留原始的所有权和权限?
gui*_*ido 587
sudo cp -rp /home/my_home /media/backup/my_home
Run Code Online (Sandbox Code Playgroud)
从 cp 联机帮助页:
-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
Run Code Online (Sandbox Code Playgroud)
stu*_*ent 112
您也可以使用rsync.
sudo rsync -a /home/my_home/ /media/backup/my_home/
Run Code Online (Sandbox Code Playgroud)
从rsync联机帮助页:
-a, --archive
This is equivalent to -rlptgoD. It is a quick way of saying you want
recursion and want to preserve almost everything (with -H being a notable
omission). The only exception to the above equivalence is when
--files-from is specified, in which case -r is not implied.
Note that -a does not preserve hardlinks, because finding multiply-linked
files is expensive. You must separately specify -H.
Run Code Online (Sandbox Code Playgroud)
请参阅此问题以了解cp和之间的比较rsync:https : //stackoverflow.com/q/6339287/406686
请注意尾部斜杠(有关详细信息,请参见联机帮助页)。
Zaz*_*Zaz 78
cp -a
Run Code Online (Sandbox Code Playgroud)
Where-a的缩写--archive— 基本上它完全按原样复制目录;文件保留其所有属性,并且不会取消引用符号链接 ( -d)。
来自man cp:
-a, --archive
same as -dR --preserve=all
Run Code Online (Sandbox Code Playgroud)
Sta*_*mer 24
我使用cp -pdRxwhich 将-p保留模式、所有权和时间戳,-d保留链接(因此您得到符号链接而不是复制的文件内容),-R递归执行并-x保留在一个文件系统上(仅当您正在复制/或具有活动挂载点的东西时才真正有用)。
PS:-R而不是-r只是习惯使用ls -lR.
Mat*_*teo 15
cp可以选择保留文件所有权。从手册页cp:
-p Cause cp to preserve the following attributes of each source file in the copy: modification
time, access time, file flags, file mode, user ID, and group ID, as allowed by permissions.
Access Control Lists (ACLs) and Extended Attributes (EAs), including resource forks, will also
be preserved.
Run Code Online (Sandbox Code Playgroud)
Bru*_*ger 13
你可以这样做:
tar cf - my_home | (cd /media/backup; sudo tar xf - )
Run Code Online (Sandbox Code Playgroud)
tar保持权限、所有权和目录结构不变,但将所有内容转换为字节流。您运行一个更改目录的“子shell”(带括号的命令),然后开始tar反转转换。字节流变成具有正确所有权和权限的目录和文件。
| 归档时间: |
|
| 查看次数: |
852891 次 |
| 最近记录: |