Using Tar, how to preserve permissions of parent folders when given just a specific file?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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:%fn"
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?
permissions terminal tar
add a comment |Â
up vote
0
down vote
favorite
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:%fn"
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?
permissions terminal tar
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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:%fn"
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?
permissions terminal tar
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:%fn"
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?
permissions terminal tar
permissions terminal tar
asked Aug 7 at 10:39
flxapps
1041
1041
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
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'; find abc/def -print0) | bsdtar -zcnf file.tgz --null -T -
add a comment |Â
up vote
0
down vote
Your umask is applied. Try:
umask 000; tar -xpzvf test.tar.gz
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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'; find abc/def -print0) | bsdtar -zcnf file.tgz --null -T -
add a comment |Â
up vote
1
down vote
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'; find abc/def -print0) | bsdtar -zcnf file.tgz --null -T -
add a comment |Â
up vote
1
down vote
up vote
1
down vote
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'; find abc/def -print0) | bsdtar -zcnf file.tgz --null -T -
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'; find abc/def -print0) | bsdtar -zcnf file.tgz --null -T -
answered Aug 7 at 12:56
Stéphane Chazelas
284k53523861
284k53523861
add a comment |Â
add a comment |Â
up vote
0
down vote
Your umask is applied. Try:
umask 000; tar -xpzvf test.tar.gz
add a comment |Â
up vote
0
down vote
Your umask is applied. Try:
umask 000; tar -xpzvf test.tar.gz
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Your umask is applied. Try:
umask 000; tar -xpzvf test.tar.gz
Your umask is applied. Try:
umask 000; tar -xpzvf test.tar.gz
answered Aug 7 at 11:49
stoney
1204
1204
add a comment |Â
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
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 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.
answered Aug 7 at 12:18
schily
9,62131437
9,62131437
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461038%2fusing-tar-how-to-preserve-permissions-of-parent-folders-when-given-just-a-speci%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password