问题
I have noticed that a tarball created on one linux does not preserve the file permissions when extracted on another linux.
How can I make tar preserve the file permissions?
回答1:
Use the p
option, both when creating the tarball and when extracting it.
回答2:
Can you try:
tar -pcvzf xxx.tar.gz
p == preserve permissions
c == create archive
v == verbose (print names while making tar)
z == gzip
f == tar file name
Source
回答3:
Having a short look at the manpage clarifies your issue:
-p, --preserve-permissions, --same-permissions
extract information about file permissions (default for superuser)
But mind, that untaring your archive on some filesystems like FAT won't preserve permissions as they don't support it.
Also the numeric owner / access time preserve might be intersting to you:
--numeric-owner
always use numbers for user/group names
--atime-preserve
preserve access times on dumped files, either by restoring the
times
来源:https://stackoverflow.com/questions/20338215/why-doesnt-tar-preserve-file-permissions