How do I gunzip to a different destination directory?











up vote
67
down vote

favorite
13












How do I gunzip to a destination directory other than the current one?



This did not work:



gunzip *.gz /putthemhere/









share|improve this question




























    up vote
    67
    down vote

    favorite
    13












    How do I gunzip to a destination directory other than the current one?



    This did not work:



    gunzip *.gz /putthemhere/









    share|improve this question


























      up vote
      67
      down vote

      favorite
      13









      up vote
      67
      down vote

      favorite
      13






      13





      How do I gunzip to a destination directory other than the current one?



      This did not work:



      gunzip *.gz /putthemhere/









      share|improve this question















      How do I gunzip to a destination directory other than the current one?



      This did not work:



      gunzip *.gz /putthemhere/






      linux unix gunzip






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 29 '14 at 19:55









      Der Hochstapler

      67k48230283




      67k48230283










      asked May 9 '10 at 23:15









      Scott Szretter

      69831324




      69831324






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          87
          down vote



          accepted










          Ask gunzip to output to standard output and redirect to a file in that directory:



          gunzip -c file.gz > /THERE/file


          zcat is a shortcut for gunzip -c.



          If you want to gunzip multiple files iterate over all files:



          for f in *.gz; do
          STEM=$(basename "${f}" .gz)
          gunzip -c "${f}" > /THERE/"${STEM}"
          done


          (here basename is used to get the part of the filename without the extension)






          share|improve this answer



















          • 2




            Creates the file, but does not preserve file ownership, permissions etc. That may be good or bad depending on your precise situation.
            – Chris Johnson
            Nov 9 '14 at 17:12


















          up vote
          1
          down vote













          You can try with > to redirect the result to the place you want.






          share|improve this answer




























            up vote
            1
            down vote













            If you need to extract a single file and write into a root-owned directory, then use sudo dd:



            zcat filename.conf.gz | sudo tee /etc/filename.conf >/dev/null


            If the file is coming from a remote source (i.e., ssh, curl https, etc), you can do it like this:



            ssh remoteserver cat filename.conf.gz | zcat | sudo tee /etc/filename.conf >/dev/null


            (Note that these examples only work for a single file, unlike the example *.gz, which is all gzipped files in the directory.)






            share|improve this answer























            • For writing with root privileges, sudo tee $filename >/dev/null is a little more idiomatic than using dd.
              – dcoles
              Nov 17 at 21:17











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fsuperuser.com%2fquestions%2f139419%2fhow-do-i-gunzip-to-a-different-destination-directory%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            87
            down vote



            accepted










            Ask gunzip to output to standard output and redirect to a file in that directory:



            gunzip -c file.gz > /THERE/file


            zcat is a shortcut for gunzip -c.



            If you want to gunzip multiple files iterate over all files:



            for f in *.gz; do
            STEM=$(basename "${f}" .gz)
            gunzip -c "${f}" > /THERE/"${STEM}"
            done


            (here basename is used to get the part of the filename without the extension)






            share|improve this answer



















            • 2




              Creates the file, but does not preserve file ownership, permissions etc. That may be good or bad depending on your precise situation.
              – Chris Johnson
              Nov 9 '14 at 17:12















            up vote
            87
            down vote



            accepted










            Ask gunzip to output to standard output and redirect to a file in that directory:



            gunzip -c file.gz > /THERE/file


            zcat is a shortcut for gunzip -c.



            If you want to gunzip multiple files iterate over all files:



            for f in *.gz; do
            STEM=$(basename "${f}" .gz)
            gunzip -c "${f}" > /THERE/"${STEM}"
            done


            (here basename is used to get the part of the filename without the extension)






            share|improve this answer



















            • 2




              Creates the file, but does not preserve file ownership, permissions etc. That may be good or bad depending on your precise situation.
              – Chris Johnson
              Nov 9 '14 at 17:12













            up vote
            87
            down vote



            accepted







            up vote
            87
            down vote



            accepted






            Ask gunzip to output to standard output and redirect to a file in that directory:



            gunzip -c file.gz > /THERE/file


            zcat is a shortcut for gunzip -c.



            If you want to gunzip multiple files iterate over all files:



            for f in *.gz; do
            STEM=$(basename "${f}" .gz)
            gunzip -c "${f}" > /THERE/"${STEM}"
            done


            (here basename is used to get the part of the filename without the extension)






            share|improve this answer














            Ask gunzip to output to standard output and redirect to a file in that directory:



            gunzip -c file.gz > /THERE/file


            zcat is a shortcut for gunzip -c.



            If you want to gunzip multiple files iterate over all files:



            for f in *.gz; do
            STEM=$(basename "${f}" .gz)
            gunzip -c "${f}" > /THERE/"${STEM}"
            done


            (here basename is used to get the part of the filename without the extension)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jul 25 '12 at 20:56

























            answered May 9 '10 at 23:23









            Benjamin Bannier

            12.7k23637




            12.7k23637








            • 2




              Creates the file, but does not preserve file ownership, permissions etc. That may be good or bad depending on your precise situation.
              – Chris Johnson
              Nov 9 '14 at 17:12














            • 2




              Creates the file, but does not preserve file ownership, permissions etc. That may be good or bad depending on your precise situation.
              – Chris Johnson
              Nov 9 '14 at 17:12








            2




            2




            Creates the file, but does not preserve file ownership, permissions etc. That may be good or bad depending on your precise situation.
            – Chris Johnson
            Nov 9 '14 at 17:12




            Creates the file, but does not preserve file ownership, permissions etc. That may be good or bad depending on your precise situation.
            – Chris Johnson
            Nov 9 '14 at 17:12












            up vote
            1
            down vote













            You can try with > to redirect the result to the place you want.






            share|improve this answer

























              up vote
              1
              down vote













              You can try with > to redirect the result to the place you want.






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                You can try with > to redirect the result to the place you want.






                share|improve this answer












                You can try with > to redirect the result to the place you want.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 9 '10 at 23:21









                jangelfdez

                20212




                20212






















                    up vote
                    1
                    down vote













                    If you need to extract a single file and write into a root-owned directory, then use sudo dd:



                    zcat filename.conf.gz | sudo tee /etc/filename.conf >/dev/null


                    If the file is coming from a remote source (i.e., ssh, curl https, etc), you can do it like this:



                    ssh remoteserver cat filename.conf.gz | zcat | sudo tee /etc/filename.conf >/dev/null


                    (Note that these examples only work for a single file, unlike the example *.gz, which is all gzipped files in the directory.)






                    share|improve this answer























                    • For writing with root privileges, sudo tee $filename >/dev/null is a little more idiomatic than using dd.
                      – dcoles
                      Nov 17 at 21:17















                    up vote
                    1
                    down vote













                    If you need to extract a single file and write into a root-owned directory, then use sudo dd:



                    zcat filename.conf.gz | sudo tee /etc/filename.conf >/dev/null


                    If the file is coming from a remote source (i.e., ssh, curl https, etc), you can do it like this:



                    ssh remoteserver cat filename.conf.gz | zcat | sudo tee /etc/filename.conf >/dev/null


                    (Note that these examples only work for a single file, unlike the example *.gz, which is all gzipped files in the directory.)






                    share|improve this answer























                    • For writing with root privileges, sudo tee $filename >/dev/null is a little more idiomatic than using dd.
                      – dcoles
                      Nov 17 at 21:17













                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    If you need to extract a single file and write into a root-owned directory, then use sudo dd:



                    zcat filename.conf.gz | sudo tee /etc/filename.conf >/dev/null


                    If the file is coming from a remote source (i.e., ssh, curl https, etc), you can do it like this:



                    ssh remoteserver cat filename.conf.gz | zcat | sudo tee /etc/filename.conf >/dev/null


                    (Note that these examples only work for a single file, unlike the example *.gz, which is all gzipped files in the directory.)






                    share|improve this answer














                    If you need to extract a single file and write into a root-owned directory, then use sudo dd:



                    zcat filename.conf.gz | sudo tee /etc/filename.conf >/dev/null


                    If the file is coming from a remote source (i.e., ssh, curl https, etc), you can do it like this:



                    ssh remoteserver cat filename.conf.gz | zcat | sudo tee /etc/filename.conf >/dev/null


                    (Note that these examples only work for a single file, unlike the example *.gz, which is all gzipped files in the directory.)







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 21 at 17:04

























                    answered Jan 9 '17 at 20:24









                    Jamieson Becker

                    23114




                    23114












                    • For writing with root privileges, sudo tee $filename >/dev/null is a little more idiomatic than using dd.
                      – dcoles
                      Nov 17 at 21:17


















                    • For writing with root privileges, sudo tee $filename >/dev/null is a little more idiomatic than using dd.
                      – dcoles
                      Nov 17 at 21:17
















                    For writing with root privileges, sudo tee $filename >/dev/null is a little more idiomatic than using dd.
                    – dcoles
                    Nov 17 at 21:17




                    For writing with root privileges, sudo tee $filename >/dev/null is a little more idiomatic than using dd.
                    – dcoles
                    Nov 17 at 21:17


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f139419%2fhow-do-i-gunzip-to-a-different-destination-directory%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

                    Plaza Victoria

                    Puebla de Zaragoza

                    Musa