Preserve ownership of entire folder hierarchy in tar?

Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I can preserve ownership of folderB and all files and folders inside when creating and extracting a tar file as follows:
tar -cpf out.tar folderA/folderB
sudo tar -xpf out.tar --same-owner
However, folderA is owned by root when extracting unless the folder already exists. Is there any way to preserve ownership of the entire folder hierarchy with tar?
permissions tar ownership
add a comment |Â
up vote
3
down vote
favorite
I can preserve ownership of folderB and all files and folders inside when creating and extracting a tar file as follows:
tar -cpf out.tar folderA/folderB
sudo tar -xpf out.tar --same-owner
However, folderA is owned by root when extracting unless the folder already exists. Is there any way to preserve ownership of the entire folder hierarchy with tar?
permissions tar ownership
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I can preserve ownership of folderB and all files and folders inside when creating and extracting a tar file as follows:
tar -cpf out.tar folderA/folderB
sudo tar -xpf out.tar --same-owner
However, folderA is owned by root when extracting unless the folder already exists. Is there any way to preserve ownership of the entire folder hierarchy with tar?
permissions tar ownership
I can preserve ownership of folderB and all files and folders inside when creating and extracting a tar file as follows:
tar -cpf out.tar folderA/folderB
sudo tar -xpf out.tar --same-owner
However, folderA is owned by root when extracting unless the folder already exists. Is there any way to preserve ownership of the entire folder hierarchy with tar?
permissions tar ownership
edited May 18 at 22:42
asked May 18 at 19:24
user276833
285
285
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
This happens because
tar -cpf out.tar folderA/folderB
doesnâÂÂt store folderA as a separate object in the tarball, so it doesnâÂÂt have any way of recording the ownership and permissions of folderA.
To preserve the ownership, you need to tell tar to do so when you create the tarball; with GNU tar at least, the following works:
tar -cpf out.tar --no-recursion folderA --recursion folderA/folderB
This stores folderA (and its permissions etc.) without recursing, and folderA/folderB with its contents.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
This happens because
tar -cpf out.tar folderA/folderB
doesnâÂÂt store folderA as a separate object in the tarball, so it doesnâÂÂt have any way of recording the ownership and permissions of folderA.
To preserve the ownership, you need to tell tar to do so when you create the tarball; with GNU tar at least, the following works:
tar -cpf out.tar --no-recursion folderA --recursion folderA/folderB
This stores folderA (and its permissions etc.) without recursing, and folderA/folderB with its contents.
add a comment |Â
up vote
2
down vote
accepted
This happens because
tar -cpf out.tar folderA/folderB
doesnâÂÂt store folderA as a separate object in the tarball, so it doesnâÂÂt have any way of recording the ownership and permissions of folderA.
To preserve the ownership, you need to tell tar to do so when you create the tarball; with GNU tar at least, the following works:
tar -cpf out.tar --no-recursion folderA --recursion folderA/folderB
This stores folderA (and its permissions etc.) without recursing, and folderA/folderB with its contents.
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
This happens because
tar -cpf out.tar folderA/folderB
doesnâÂÂt store folderA as a separate object in the tarball, so it doesnâÂÂt have any way of recording the ownership and permissions of folderA.
To preserve the ownership, you need to tell tar to do so when you create the tarball; with GNU tar at least, the following works:
tar -cpf out.tar --no-recursion folderA --recursion folderA/folderB
This stores folderA (and its permissions etc.) without recursing, and folderA/folderB with its contents.
This happens because
tar -cpf out.tar folderA/folderB
doesnâÂÂt store folderA as a separate object in the tarball, so it doesnâÂÂt have any way of recording the ownership and permissions of folderA.
To preserve the ownership, you need to tell tar to do so when you create the tarball; with GNU tar at least, the following works:
tar -cpf out.tar --no-recursion folderA --recursion folderA/folderB
This stores folderA (and its permissions etc.) without recursing, and folderA/folderB with its contents.
answered May 18 at 19:45
Stephen Kitt
140k22302363
140k22302363
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%2f444686%2fpreserve-ownership-of-entire-folder-hierarchy-in-tar%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