0

Say, I have a folder with some fancy permissions:

mkdir abc
mkdir abc/def
chmod 777 abc

Now I want to create a backup:

tar -cpzvf test.tar.gz abc/def/

Now let's remove abc/ and restore it from the archive:

rm -rf abc/
tar -xpzvf test.tar.gz

abc/ will not have the original permissions anymore:

find abc -printf "%m:%f\n"
755:abc

I know that if I would create the tar file by providing abc/ (not abc/def/) as parameter, it would restore the permissions of both folders just fine. However, in my case I need to explicitly provide abc/def/ as parameter. Is there a way to achieve the same result?

1

To follow-up on @schily's fine answer, to add the top-level directory abc to the archive, without adding any of its subdirectories other than def, with GNU tar, you'd do:

tar -zcf file.tgz --no-recursion abc --recursion abc/def

With libarchive's bsdtar, or pax, you can always revert to have find generate the exact list of files you want:

(printf 'abc\0'; find abc/def -print0) | bsdtar -zcnf file.tgz --null -T -
0

Your umask is applied. Try:

umask 000; tar -xpzvf test.tar.gz

0

Your problems is that the directory abc is not in the archive and thus cannot be restored from the archive.

Since it is needed but missing, tar creates it with default permissions under your credentials.

If you like to restore the permissions from abc as well, you need to put it into the archive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.