Using Tar, how to preserve permissions of parent folders when given just a specific file?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question

























    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?










    share|improve this question























      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?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 7 at 10:39









      flxapps

      1041




      1041




















          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 -





          share|improve this answer



























            up vote
            0
            down vote













            Your umask is applied. Try:



            umask 000; tar -xpzvf test.tar.gz






            share|improve this answer



























              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.






              share|improve this answer




















                Your Answer







                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "106"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                 

                draft saved


                draft discarded


















                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






























                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 -





                share|improve this answer
























                  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 -





                  share|improve this answer






















                    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 -





                    share|improve this answer












                    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 -






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 7 at 12:56









                    Stéphane Chazelas

                    284k53523861




                    284k53523861






















                        up vote
                        0
                        down vote













                        Your umask is applied. Try:



                        umask 000; tar -xpzvf test.tar.gz






                        share|improve this answer
























                          up vote
                          0
                          down vote













                          Your umask is applied. Try:



                          umask 000; tar -xpzvf test.tar.gz






                          share|improve this answer






















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            Your umask is applied. Try:



                            umask 000; tar -xpzvf test.tar.gz






                            share|improve this answer












                            Your umask is applied. Try:



                            umask 000; tar -xpzvf test.tar.gz







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Aug 7 at 11:49









                            stoney

                            1204




                            1204




















                                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.






                                share|improve this answer
























                                  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.






                                  share|improve this answer






















                                    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.






                                    share|improve this answer












                                    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.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Aug 7 at 12:18









                                    schily

                                    9,62131437




                                    9,62131437



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        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













































































                                        Popular posts from this blog

                                        How to check contact read email or not when send email to Individual?

                                        Displaying single band from multi-band raster using QGIS

                                        How many registers does an x86_64 CPU actually have?