Tar directory into archive with the same name as the directory?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Is there an elegant one-liner to tar/archive the whole directory and delete it afterwards? So far I came up with bulky solutions.



from:



# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest


to:



# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest.tar.gz


EDIT #1



The problem is I do not know the name of the directory in advance (it is dynamically created, so next time it will be different), but it will always be the only directory here.







share|improve this question





















  • You say you have a solution (but it is too big). But you don't show it.
    – ctrl-alt-delor
    Jul 5 at 10:16














up vote
1
down vote

favorite












Is there an elegant one-liner to tar/archive the whole directory and delete it afterwards? So far I came up with bulky solutions.



from:



# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest


to:



# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest.tar.gz


EDIT #1



The problem is I do not know the name of the directory in advance (it is dynamically created, so next time it will be different), but it will always be the only directory here.







share|improve this question





















  • You say you have a solution (but it is too big). But you don't show it.
    – ctrl-alt-delor
    Jul 5 at 10:16












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Is there an elegant one-liner to tar/archive the whole directory and delete it afterwards? So far I came up with bulky solutions.



from:



# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest


to:



# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest.tar.gz


EDIT #1



The problem is I do not know the name of the directory in advance (it is dynamically created, so next time it will be different), but it will always be the only directory here.







share|improve this question













Is there an elegant one-liner to tar/archive the whole directory and delete it afterwards? So far I came up with bulky solutions.



from:



# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest


to:



# ls -la
drwxr-xr-x 3 root root 4096 Jul 4 15:01 .
drwxr-xr-x 6 root root 4096 Jul 4 14:54 ..
drwxr-xr-x 4 root root 4096 Jul 4 14:59 stresstest.tar.gz


EDIT #1



The problem is I do not know the name of the directory in advance (it is dynamically created, so next time it will be different), but it will always be the only directory here.









share|improve this question












share|improve this question




share|improve this question








edited Jul 5 at 17:31









slm♦

233k65479651




233k65479651









asked Jul 5 at 9:04









Eugene A

1155




1155











  • You say you have a solution (but it is too big). But you don't show it.
    – ctrl-alt-delor
    Jul 5 at 10:16
















  • You say you have a solution (but it is too big). But you don't show it.
    – ctrl-alt-delor
    Jul 5 at 10:16















You say you have a solution (but it is too big). But you don't show it.
– ctrl-alt-delor
Jul 5 at 10:16




You say you have a solution (but it is too big). But you don't show it.
– ctrl-alt-delor
Jul 5 at 10:16










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done


Example



$ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
stresstest/
stresstest/file1
stresstest/file2
stresstest/file3

$ ll
total 4
-rw-r--r-- 1 root root 162 Jul 5 05:18 stresstest.tgz





share|improve this answer






























    up vote
    0
    down vote













    (dir="stresstest"; tar zcvf $dir.tgz $dir; rm -rf $dir)





    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%2f453560%2ftar-directory-into-archive-with-the-same-name-as-the-directory%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote



      accepted










      $ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done


      Example



      $ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
      stresstest/
      stresstest/file1
      stresstest/file2
      stresstest/file3

      $ ll
      total 4
      -rw-r--r-- 1 root root 162 Jul 5 05:18 stresstest.tgz





      share|improve this answer



























        up vote
        2
        down vote



        accepted










        $ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done


        Example



        $ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
        stresstest/
        stresstest/file1
        stresstest/file2
        stresstest/file3

        $ ll
        total 4
        -rw-r--r-- 1 root root 162 Jul 5 05:18 stresstest.tgz





        share|improve this answer

























          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          $ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done


          Example



          $ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
          stresstest/
          stresstest/file1
          stresstest/file2
          stresstest/file3

          $ ll
          total 4
          -rw-r--r-- 1 root root 162 Jul 5 05:18 stresstest.tgz





          share|improve this answer















          $ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done


          Example



          $ for i in *;do tar zcvf $i.tgz $i; rm -fr $i;done
          stresstest/
          stresstest/file1
          stresstest/file2
          stresstest/file3

          $ ll
          total 4
          -rw-r--r-- 1 root root 162 Jul 5 05:18 stresstest.tgz






          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Jul 5 at 9:19


























          answered Jul 5 at 9:12









          slm♦

          233k65479651




          233k65479651






















              up vote
              0
              down vote













              (dir="stresstest"; tar zcvf $dir.tgz $dir; rm -rf $dir)





              share|improve this answer

























                up vote
                0
                down vote













                (dir="stresstest"; tar zcvf $dir.tgz $dir; rm -rf $dir)





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  (dir="stresstest"; tar zcvf $dir.tgz $dir; rm -rf $dir)





                  share|improve this answer













                  (dir="stresstest"; tar zcvf $dir.tgz $dir; rm -rf $dir)






                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered Jul 5 at 10:19









                  ctrl-alt-delor

                  8,68331947




                  8,68331947






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453560%2ftar-directory-into-archive-with-the-same-name-as-the-directory%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)