Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why doesn't tar preserve file permissions? [closed]

Tags:

linux

tar

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?

like image 636
Andres Gonzalez Avatar asked Dec 02 '13 21:12

Andres Gonzalez


People also ask

Does tar preserve file permissions?

By default, tar will preserve file permissions and ownership when creating the archive. To extract file permissions and ownership, you will need to run tar as root when extracting, since changing file ownership usually requires superuser privileges.

How do you preserve permissions?

Preserve File Permissions Using cp You can use the -p option of cp to preserve the mode, ownership, and timestamps of the file. However, you will need to add the -r option to this command when dealing with directories. It will copy all sub-directories and individual files, keeping their original permissions intact.

Does tar preserve symlinks?

Preserving the symbolic linksBy default, the tar utility archives the symbolic links such that they can be restored when the archive is unpacked and saves hard-linked files only once within the archive. From the size of the file archive.

Does tar keep original file?

The * is what tells tar to include all files and local directories recursively. The tar command will never move or delete any of the original directories and files you feed it – it only makes archived copies. You should also note that using a dot (.)


2 Answers

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

like image 149
Pippin Avatar answered Sep 21 '22 07:09

Pippin


Use the p option, both when creating the tarball and when extracting it.

like image 21
Robin Green Avatar answered Sep 17 '22 07:09

Robin Green