gzip multiple files and rename them

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











up vote
1
down vote

favorite












I have to gzip multiple files in a directory and rename them. I dont want to zip them into a single zip file. i.e.



gzip:



ABCDEPG01_20171120234905_59977
ABCDEPG02_20171120234905_59978
ABCDEPG03_20171120234905_59979


to:



ABCDEFG_DWH_ABCDEPG01_20171120234905_59977.gz
ABCDEFG_DWH_ABCDEPG02_20171120234905_59978.gz
ABCDEFG_DWH_ABCDEPG03_20171120234905_59979.gz









share|improve this question



























    up vote
    1
    down vote

    favorite












    I have to gzip multiple files in a directory and rename them. I dont want to zip them into a single zip file. i.e.



    gzip:



    ABCDEPG01_20171120234905_59977
    ABCDEPG02_20171120234905_59978
    ABCDEPG03_20171120234905_59979


    to:



    ABCDEFG_DWH_ABCDEPG01_20171120234905_59977.gz
    ABCDEFG_DWH_ABCDEPG02_20171120234905_59978.gz
    ABCDEFG_DWH_ABCDEPG03_20171120234905_59979.gz









    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have to gzip multiple files in a directory and rename them. I dont want to zip them into a single zip file. i.e.



      gzip:



      ABCDEPG01_20171120234905_59977
      ABCDEPG02_20171120234905_59978
      ABCDEPG03_20171120234905_59979


      to:



      ABCDEFG_DWH_ABCDEPG01_20171120234905_59977.gz
      ABCDEFG_DWH_ABCDEPG02_20171120234905_59978.gz
      ABCDEFG_DWH_ABCDEPG03_20171120234905_59979.gz









      share|improve this question















      I have to gzip multiple files in a directory and rename them. I dont want to zip them into a single zip file. i.e.



      gzip:



      ABCDEPG01_20171120234905_59977
      ABCDEPG02_20171120234905_59978
      ABCDEPG03_20171120234905_59979


      to:



      ABCDEFG_DWH_ABCDEPG01_20171120234905_59977.gz
      ABCDEFG_DWH_ABCDEPG02_20171120234905_59978.gz
      ABCDEFG_DWH_ABCDEPG03_20171120234905_59979.gz






      files gzip






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      don_crissti

      48.6k15129158




      48.6k15129158










      asked 2 days ago









      Scott Mick

      92




      92




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Are you just adding a prefix? Then something like this could do:



          prefix=ABCDEFG_DWH_
          for f in ABCDEPG*; do
          gzip < "$f" > "$prefix$f.gz" && rm -- "$f"
          done





          share|improve this answer




















          • Yes, just adding a prefix. thanks!
            – Scott Mick
            2 days ago










          • @ScottMick If this solves your issue, please consider accepting the answer.
            – Kusalananda
            2 days ago

















          up vote
          1
          down vote













          An alternative approach to that of ilkkachu which only uses gzip (as found on OpenBSD systems only):



          for name in ABCDEPG*; do
          gzip -o "ABCDEFG_DWH_$name.gz" -- "$name"
          done


          Or in parallel with xargs (here, four parallel tasks will be spawned):



          printf '%sn' ABCDEPG* | xargs -P 4 -I gzip -o ABCDEFG_DWH_.gz -- 


          That parallel xargs thing for less advanced implementations of gzip (this would work on Linux):



          printf '%sn' ABCDEPG* |
          xargs -P 4 -I
          sh -c 'gzip -- "$1" && mv -- "$1.gz" "ABCDEFG_DWH_$1.gz"' sh





          share|improve this answer






















          • @don_crissti /usr/bin/gzip in the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
            – Kusalananda
            2 days ago






          • 1




            @don_crissti But, but, everyone's using OpenBSD, suuurely?
            – Kusalananda
            2 days ago










          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: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          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%2f481996%2fgzip-multiple-files-and-rename-them%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          Are you just adding a prefix? Then something like this could do:



          prefix=ABCDEFG_DWH_
          for f in ABCDEPG*; do
          gzip < "$f" > "$prefix$f.gz" && rm -- "$f"
          done





          share|improve this answer




















          • Yes, just adding a prefix. thanks!
            – Scott Mick
            2 days ago










          • @ScottMick If this solves your issue, please consider accepting the answer.
            – Kusalananda
            2 days ago














          up vote
          3
          down vote



          accepted










          Are you just adding a prefix? Then something like this could do:



          prefix=ABCDEFG_DWH_
          for f in ABCDEPG*; do
          gzip < "$f" > "$prefix$f.gz" && rm -- "$f"
          done





          share|improve this answer




















          • Yes, just adding a prefix. thanks!
            – Scott Mick
            2 days ago










          • @ScottMick If this solves your issue, please consider accepting the answer.
            – Kusalananda
            2 days ago












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          Are you just adding a prefix? Then something like this could do:



          prefix=ABCDEFG_DWH_
          for f in ABCDEPG*; do
          gzip < "$f" > "$prefix$f.gz" && rm -- "$f"
          done





          share|improve this answer












          Are you just adding a prefix? Then something like this could do:



          prefix=ABCDEFG_DWH_
          for f in ABCDEPG*; do
          gzip < "$f" > "$prefix$f.gz" && rm -- "$f"
          done






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          ilkkachu

          53.6k781146




          53.6k781146











          • Yes, just adding a prefix. thanks!
            – Scott Mick
            2 days ago










          • @ScottMick If this solves your issue, please consider accepting the answer.
            – Kusalananda
            2 days ago
















          • Yes, just adding a prefix. thanks!
            – Scott Mick
            2 days ago










          • @ScottMick If this solves your issue, please consider accepting the answer.
            – Kusalananda
            2 days ago















          Yes, just adding a prefix. thanks!
          – Scott Mick
          2 days ago




          Yes, just adding a prefix. thanks!
          – Scott Mick
          2 days ago












          @ScottMick If this solves your issue, please consider accepting the answer.
          – Kusalananda
          2 days ago




          @ScottMick If this solves your issue, please consider accepting the answer.
          – Kusalananda
          2 days ago












          up vote
          1
          down vote













          An alternative approach to that of ilkkachu which only uses gzip (as found on OpenBSD systems only):



          for name in ABCDEPG*; do
          gzip -o "ABCDEFG_DWH_$name.gz" -- "$name"
          done


          Or in parallel with xargs (here, four parallel tasks will be spawned):



          printf '%sn' ABCDEPG* | xargs -P 4 -I gzip -o ABCDEFG_DWH_.gz -- 


          That parallel xargs thing for less advanced implementations of gzip (this would work on Linux):



          printf '%sn' ABCDEPG* |
          xargs -P 4 -I
          sh -c 'gzip -- "$1" && mv -- "$1.gz" "ABCDEFG_DWH_$1.gz"' sh





          share|improve this answer






















          • @don_crissti /usr/bin/gzip in the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
            – Kusalananda
            2 days ago






          • 1




            @don_crissti But, but, everyone's using OpenBSD, suuurely?
            – Kusalananda
            2 days ago














          up vote
          1
          down vote













          An alternative approach to that of ilkkachu which only uses gzip (as found on OpenBSD systems only):



          for name in ABCDEPG*; do
          gzip -o "ABCDEFG_DWH_$name.gz" -- "$name"
          done


          Or in parallel with xargs (here, four parallel tasks will be spawned):



          printf '%sn' ABCDEPG* | xargs -P 4 -I gzip -o ABCDEFG_DWH_.gz -- 


          That parallel xargs thing for less advanced implementations of gzip (this would work on Linux):



          printf '%sn' ABCDEPG* |
          xargs -P 4 -I
          sh -c 'gzip -- "$1" && mv -- "$1.gz" "ABCDEFG_DWH_$1.gz"' sh





          share|improve this answer






















          • @don_crissti /usr/bin/gzip in the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
            – Kusalananda
            2 days ago






          • 1




            @don_crissti But, but, everyone's using OpenBSD, suuurely?
            – Kusalananda
            2 days ago












          up vote
          1
          down vote










          up vote
          1
          down vote









          An alternative approach to that of ilkkachu which only uses gzip (as found on OpenBSD systems only):



          for name in ABCDEPG*; do
          gzip -o "ABCDEFG_DWH_$name.gz" -- "$name"
          done


          Or in parallel with xargs (here, four parallel tasks will be spawned):



          printf '%sn' ABCDEPG* | xargs -P 4 -I gzip -o ABCDEFG_DWH_.gz -- 


          That parallel xargs thing for less advanced implementations of gzip (this would work on Linux):



          printf '%sn' ABCDEPG* |
          xargs -P 4 -I
          sh -c 'gzip -- "$1" && mv -- "$1.gz" "ABCDEFG_DWH_$1.gz"' sh





          share|improve this answer














          An alternative approach to that of ilkkachu which only uses gzip (as found on OpenBSD systems only):



          for name in ABCDEPG*; do
          gzip -o "ABCDEFG_DWH_$name.gz" -- "$name"
          done


          Or in parallel with xargs (here, four parallel tasks will be spawned):



          printf '%sn' ABCDEPG* | xargs -P 4 -I gzip -o ABCDEFG_DWH_.gz -- 


          That parallel xargs thing for less advanced implementations of gzip (this would work on Linux):



          printf '%sn' ABCDEPG* |
          xargs -P 4 -I
          sh -c 'gzip -- "$1" && mv -- "$1.gz" "ABCDEFG_DWH_$1.gz"' sh






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          Kusalananda

          115k15218351




          115k15218351











          • @don_crissti /usr/bin/gzip in the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
            – Kusalananda
            2 days ago






          • 1




            @don_crissti But, but, everyone's using OpenBSD, suuurely?
            – Kusalananda
            2 days ago
















          • @don_crissti /usr/bin/gzip in the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
            – Kusalananda
            2 days ago






          • 1




            @don_crissti But, but, everyone's using OpenBSD, suuurely?
            – Kusalananda
            2 days ago















          @don_crissti /usr/bin/gzip in the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
          – Kusalananda
          2 days ago




          @don_crissti /usr/bin/gzip in the OpenBSD 6.4 base system. GNU systems doesn't have this!? Huh. I'll make a note in the answer. Thanks!
          – Kusalananda
          2 days ago




          1




          1




          @don_crissti But, but, everyone's using OpenBSD, suuurely?
          – Kusalananda
          2 days ago




          @don_crissti But, but, everyone's using OpenBSD, suuurely?
          – Kusalananda
          2 days ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481996%2fgzip-multiple-files-and-rename-them%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)