gzip 2 files into one file












6














I want to gzip two or more files into one file, I checked this and this but both have files like: n1.txt, n2.txt, ... but my filenames are completely different, like: file.mp4, bar.txt, foo.jpeg and I want to gzip them all and put the output into one file. This didn't help too:



gzip -c file.mp4 > test.gz
gzip -c bar.txt >> test.gz


Do I have to tar them first?



And another question: In tar files, we can watch inner files without decompression using:



tar -tvf filename.tar


Is there anyway to do this with gzip or bzip2?










share|improve this question





























    6














    I want to gzip two or more files into one file, I checked this and this but both have files like: n1.txt, n2.txt, ... but my filenames are completely different, like: file.mp4, bar.txt, foo.jpeg and I want to gzip them all and put the output into one file. This didn't help too:



    gzip -c file.mp4 > test.gz
    gzip -c bar.txt >> test.gz


    Do I have to tar them first?



    And another question: In tar files, we can watch inner files without decompression using:



    tar -tvf filename.tar


    Is there anyway to do this with gzip or bzip2?










    share|improve this question



























      6












      6








      6


      1





      I want to gzip two or more files into one file, I checked this and this but both have files like: n1.txt, n2.txt, ... but my filenames are completely different, like: file.mp4, bar.txt, foo.jpeg and I want to gzip them all and put the output into one file. This didn't help too:



      gzip -c file.mp4 > test.gz
      gzip -c bar.txt >> test.gz


      Do I have to tar them first?



      And another question: In tar files, we can watch inner files without decompression using:



      tar -tvf filename.tar


      Is there anyway to do this with gzip or bzip2?










      share|improve this question















      I want to gzip two or more files into one file, I checked this and this but both have files like: n1.txt, n2.txt, ... but my filenames are completely different, like: file.mp4, bar.txt, foo.jpeg and I want to gzip them all and put the output into one file. This didn't help too:



      gzip -c file.mp4 > test.gz
      gzip -c bar.txt >> test.gz


      Do I have to tar them first?



      And another question: In tar files, we can watch inner files without decompression using:



      tar -tvf filename.tar


      Is there anyway to do this with gzip or bzip2?







      command-line tar gzip bzip2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 19 at 7:39









      dessert

      22k55997




      22k55997










      asked Dec 19 at 6:48









      Mohammad Kholghi

      577




      577






















          2 Answers
          2






          active

          oldest

          votes


















          11














          Unlike ZIP, RAR or 7-Zip, for example, gzip can only compress one file. As you’ve already noted, there is the tar program which can serialize multiple files into one which makes them ready for gzip. The traditional Unix philosophy prefers to use multiple simpler and more specialized tools than one monolithic and complicated. In this case, it results in using tar and gzip consecutively, resulting in a .tar.gz (or .tgz) file.



          However, GNU tar includes the -z option which compresses the result of the traditional tar using gzip in just one command.



          .tar.gz files are mostly created using the -czvf options:





          • create a new archive

          • gzip (alternatives: j for bzip2, J for xz)


          • verbose (list processed files; optional)

          • output file (the following argument specifies the output file)


          In your example, you can use the command:



          tar -czvf test.tar.gz file.mp4 bar.txt





          Is there any way to watch inner files without decompression with gzip or bzip2?




          Yes, your command also works for a .tar.gz file:



          tar -tvf test.tar.gz


          Further reading




          • GNU TAR Manual page

          • 10 quick tar command examples to create/extract archives in Linux






          share|improve this answer























          • What a great answer
            – progo
            Dec 19 at 14:00






          • 1




            The combination of two tools has also allowed the replacement of the compression method with others more efficient for a specific need. Modern versions of tar knows many compressors and can transparently invoke them when needed.
            – Thorbjørn Ravn Andersen
            Dec 19 at 14:54








          • 2




            Little known fact: It is possible to compress multiple files with gzip. But it's not very useful since when decompressing such a file with gunzip it will just append all the original files into a single file. If you type echo Foo > a ; gzip a you will have a file called a.gz which contains both the name and timestamp of the original a file. If you then type echo Bar > b ; gzip b ; cat a.gz b.gz >combined.gz you will have a combined.gz file which contains all the information needed to reconstruct a and b with their original names, contents, and timestamps.
            – kasperd
            Dec 19 at 15:54



















          4














          gzip is a compressor, not an archiver, but it works well with tar



          tar -cvzf file.tar.gz path-to-files-or-directories-to-compress


          See man tar



          Compression options
          -a, --auto-compress
          Use archive suffix to determine the compression program.

          -I, --use-compress-program=COMMAND
          Filter data through COMMAND. It must accept the -d option, for
          decompression. The argument can contain command line options.

          -j, --bzip2
          Filter the archive through bzip2(1).

          -J, --xz
          Filter the archive through xz(1).

          --lzip Filter the archive through lzip(1).

          --lzma Filter the archive through lzma(1).

          --lzop Filter the archive through lzop(1).

          --no-auto-compress
          Do not use archive suffix to determine the compression program.

          -z, --gzip, --gunzip, --ungzip
          Filter the archive through gzip(1).

          -Z, --compress, --uncompress
          Filter the archive through compress(1).




          And yes, you can watch compressed archives the same way.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            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',
            autoActivateHeartbeat: false,
            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%2faskubuntu.com%2fquestions%2f1103018%2fgzip-2-files-into-one-file%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









            11














            Unlike ZIP, RAR or 7-Zip, for example, gzip can only compress one file. As you’ve already noted, there is the tar program which can serialize multiple files into one which makes them ready for gzip. The traditional Unix philosophy prefers to use multiple simpler and more specialized tools than one monolithic and complicated. In this case, it results in using tar and gzip consecutively, resulting in a .tar.gz (or .tgz) file.



            However, GNU tar includes the -z option which compresses the result of the traditional tar using gzip in just one command.



            .tar.gz files are mostly created using the -czvf options:





            • create a new archive

            • gzip (alternatives: j for bzip2, J for xz)


            • verbose (list processed files; optional)

            • output file (the following argument specifies the output file)


            In your example, you can use the command:



            tar -czvf test.tar.gz file.mp4 bar.txt





            Is there any way to watch inner files without decompression with gzip or bzip2?




            Yes, your command also works for a .tar.gz file:



            tar -tvf test.tar.gz


            Further reading




            • GNU TAR Manual page

            • 10 quick tar command examples to create/extract archives in Linux






            share|improve this answer























            • What a great answer
              – progo
              Dec 19 at 14:00






            • 1




              The combination of two tools has also allowed the replacement of the compression method with others more efficient for a specific need. Modern versions of tar knows many compressors and can transparently invoke them when needed.
              – Thorbjørn Ravn Andersen
              Dec 19 at 14:54








            • 2




              Little known fact: It is possible to compress multiple files with gzip. But it's not very useful since when decompressing such a file with gunzip it will just append all the original files into a single file. If you type echo Foo > a ; gzip a you will have a file called a.gz which contains both the name and timestamp of the original a file. If you then type echo Bar > b ; gzip b ; cat a.gz b.gz >combined.gz you will have a combined.gz file which contains all the information needed to reconstruct a and b with their original names, contents, and timestamps.
              – kasperd
              Dec 19 at 15:54
















            11














            Unlike ZIP, RAR or 7-Zip, for example, gzip can only compress one file. As you’ve already noted, there is the tar program which can serialize multiple files into one which makes them ready for gzip. The traditional Unix philosophy prefers to use multiple simpler and more specialized tools than one monolithic and complicated. In this case, it results in using tar and gzip consecutively, resulting in a .tar.gz (or .tgz) file.



            However, GNU tar includes the -z option which compresses the result of the traditional tar using gzip in just one command.



            .tar.gz files are mostly created using the -czvf options:





            • create a new archive

            • gzip (alternatives: j for bzip2, J for xz)


            • verbose (list processed files; optional)

            • output file (the following argument specifies the output file)


            In your example, you can use the command:



            tar -czvf test.tar.gz file.mp4 bar.txt





            Is there any way to watch inner files without decompression with gzip or bzip2?




            Yes, your command also works for a .tar.gz file:



            tar -tvf test.tar.gz


            Further reading




            • GNU TAR Manual page

            • 10 quick tar command examples to create/extract archives in Linux






            share|improve this answer























            • What a great answer
              – progo
              Dec 19 at 14:00






            • 1




              The combination of two tools has also allowed the replacement of the compression method with others more efficient for a specific need. Modern versions of tar knows many compressors and can transparently invoke them when needed.
              – Thorbjørn Ravn Andersen
              Dec 19 at 14:54








            • 2




              Little known fact: It is possible to compress multiple files with gzip. But it's not very useful since when decompressing such a file with gunzip it will just append all the original files into a single file. If you type echo Foo > a ; gzip a you will have a file called a.gz which contains both the name and timestamp of the original a file. If you then type echo Bar > b ; gzip b ; cat a.gz b.gz >combined.gz you will have a combined.gz file which contains all the information needed to reconstruct a and b with their original names, contents, and timestamps.
              – kasperd
              Dec 19 at 15:54














            11












            11








            11






            Unlike ZIP, RAR or 7-Zip, for example, gzip can only compress one file. As you’ve already noted, there is the tar program which can serialize multiple files into one which makes them ready for gzip. The traditional Unix philosophy prefers to use multiple simpler and more specialized tools than one monolithic and complicated. In this case, it results in using tar and gzip consecutively, resulting in a .tar.gz (or .tgz) file.



            However, GNU tar includes the -z option which compresses the result of the traditional tar using gzip in just one command.



            .tar.gz files are mostly created using the -czvf options:





            • create a new archive

            • gzip (alternatives: j for bzip2, J for xz)


            • verbose (list processed files; optional)

            • output file (the following argument specifies the output file)


            In your example, you can use the command:



            tar -czvf test.tar.gz file.mp4 bar.txt





            Is there any way to watch inner files without decompression with gzip or bzip2?




            Yes, your command also works for a .tar.gz file:



            tar -tvf test.tar.gz


            Further reading




            • GNU TAR Manual page

            • 10 quick tar command examples to create/extract archives in Linux






            share|improve this answer














            Unlike ZIP, RAR or 7-Zip, for example, gzip can only compress one file. As you’ve already noted, there is the tar program which can serialize multiple files into one which makes them ready for gzip. The traditional Unix philosophy prefers to use multiple simpler and more specialized tools than one monolithic and complicated. In this case, it results in using tar and gzip consecutively, resulting in a .tar.gz (or .tgz) file.



            However, GNU tar includes the -z option which compresses the result of the traditional tar using gzip in just one command.



            .tar.gz files are mostly created using the -czvf options:





            • create a new archive

            • gzip (alternatives: j for bzip2, J for xz)


            • verbose (list processed files; optional)

            • output file (the following argument specifies the output file)


            In your example, you can use the command:



            tar -czvf test.tar.gz file.mp4 bar.txt





            Is there any way to watch inner files without decompression with gzip or bzip2?




            Yes, your command also works for a .tar.gz file:



            tar -tvf test.tar.gz


            Further reading




            • GNU TAR Manual page

            • 10 quick tar command examples to create/extract archives in Linux







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 19 at 14:01









            progo

            1236




            1236










            answered Dec 19 at 8:54









            Melebius

            4,38251838




            4,38251838












            • What a great answer
              – progo
              Dec 19 at 14:00






            • 1




              The combination of two tools has also allowed the replacement of the compression method with others more efficient for a specific need. Modern versions of tar knows many compressors and can transparently invoke them when needed.
              – Thorbjørn Ravn Andersen
              Dec 19 at 14:54








            • 2




              Little known fact: It is possible to compress multiple files with gzip. But it's not very useful since when decompressing such a file with gunzip it will just append all the original files into a single file. If you type echo Foo > a ; gzip a you will have a file called a.gz which contains both the name and timestamp of the original a file. If you then type echo Bar > b ; gzip b ; cat a.gz b.gz >combined.gz you will have a combined.gz file which contains all the information needed to reconstruct a and b with their original names, contents, and timestamps.
              – kasperd
              Dec 19 at 15:54


















            • What a great answer
              – progo
              Dec 19 at 14:00






            • 1




              The combination of two tools has also allowed the replacement of the compression method with others more efficient for a specific need. Modern versions of tar knows many compressors and can transparently invoke them when needed.
              – Thorbjørn Ravn Andersen
              Dec 19 at 14:54








            • 2




              Little known fact: It is possible to compress multiple files with gzip. But it's not very useful since when decompressing such a file with gunzip it will just append all the original files into a single file. If you type echo Foo > a ; gzip a you will have a file called a.gz which contains both the name and timestamp of the original a file. If you then type echo Bar > b ; gzip b ; cat a.gz b.gz >combined.gz you will have a combined.gz file which contains all the information needed to reconstruct a and b with their original names, contents, and timestamps.
              – kasperd
              Dec 19 at 15:54
















            What a great answer
            – progo
            Dec 19 at 14:00




            What a great answer
            – progo
            Dec 19 at 14:00




            1




            1




            The combination of two tools has also allowed the replacement of the compression method with others more efficient for a specific need. Modern versions of tar knows many compressors and can transparently invoke them when needed.
            – Thorbjørn Ravn Andersen
            Dec 19 at 14:54






            The combination of two tools has also allowed the replacement of the compression method with others more efficient for a specific need. Modern versions of tar knows many compressors and can transparently invoke them when needed.
            – Thorbjørn Ravn Andersen
            Dec 19 at 14:54






            2




            2




            Little known fact: It is possible to compress multiple files with gzip. But it's not very useful since when decompressing such a file with gunzip it will just append all the original files into a single file. If you type echo Foo > a ; gzip a you will have a file called a.gz which contains both the name and timestamp of the original a file. If you then type echo Bar > b ; gzip b ; cat a.gz b.gz >combined.gz you will have a combined.gz file which contains all the information needed to reconstruct a and b with their original names, contents, and timestamps.
            – kasperd
            Dec 19 at 15:54




            Little known fact: It is possible to compress multiple files with gzip. But it's not very useful since when decompressing such a file with gunzip it will just append all the original files into a single file. If you type echo Foo > a ; gzip a you will have a file called a.gz which contains both the name and timestamp of the original a file. If you then type echo Bar > b ; gzip b ; cat a.gz b.gz >combined.gz you will have a combined.gz file which contains all the information needed to reconstruct a and b with their original names, contents, and timestamps.
            – kasperd
            Dec 19 at 15:54













            4














            gzip is a compressor, not an archiver, but it works well with tar



            tar -cvzf file.tar.gz path-to-files-or-directories-to-compress


            See man tar



            Compression options
            -a, --auto-compress
            Use archive suffix to determine the compression program.

            -I, --use-compress-program=COMMAND
            Filter data through COMMAND. It must accept the -d option, for
            decompression. The argument can contain command line options.

            -j, --bzip2
            Filter the archive through bzip2(1).

            -J, --xz
            Filter the archive through xz(1).

            --lzip Filter the archive through lzip(1).

            --lzma Filter the archive through lzma(1).

            --lzop Filter the archive through lzop(1).

            --no-auto-compress
            Do not use archive suffix to determine the compression program.

            -z, --gzip, --gunzip, --ungzip
            Filter the archive through gzip(1).

            -Z, --compress, --uncompress
            Filter the archive through compress(1).




            And yes, you can watch compressed archives the same way.






            share|improve this answer


























              4














              gzip is a compressor, not an archiver, but it works well with tar



              tar -cvzf file.tar.gz path-to-files-or-directories-to-compress


              See man tar



              Compression options
              -a, --auto-compress
              Use archive suffix to determine the compression program.

              -I, --use-compress-program=COMMAND
              Filter data through COMMAND. It must accept the -d option, for
              decompression. The argument can contain command line options.

              -j, --bzip2
              Filter the archive through bzip2(1).

              -J, --xz
              Filter the archive through xz(1).

              --lzip Filter the archive through lzip(1).

              --lzma Filter the archive through lzma(1).

              --lzop Filter the archive through lzop(1).

              --no-auto-compress
              Do not use archive suffix to determine the compression program.

              -z, --gzip, --gunzip, --ungzip
              Filter the archive through gzip(1).

              -Z, --compress, --uncompress
              Filter the archive through compress(1).




              And yes, you can watch compressed archives the same way.






              share|improve this answer
























                4












                4








                4






                gzip is a compressor, not an archiver, but it works well with tar



                tar -cvzf file.tar.gz path-to-files-or-directories-to-compress


                See man tar



                Compression options
                -a, --auto-compress
                Use archive suffix to determine the compression program.

                -I, --use-compress-program=COMMAND
                Filter data through COMMAND. It must accept the -d option, for
                decompression. The argument can contain command line options.

                -j, --bzip2
                Filter the archive through bzip2(1).

                -J, --xz
                Filter the archive through xz(1).

                --lzip Filter the archive through lzip(1).

                --lzma Filter the archive through lzma(1).

                --lzop Filter the archive through lzop(1).

                --no-auto-compress
                Do not use archive suffix to determine the compression program.

                -z, --gzip, --gunzip, --ungzip
                Filter the archive through gzip(1).

                -Z, --compress, --uncompress
                Filter the archive through compress(1).




                And yes, you can watch compressed archives the same way.






                share|improve this answer












                gzip is a compressor, not an archiver, but it works well with tar



                tar -cvzf file.tar.gz path-to-files-or-directories-to-compress


                See man tar



                Compression options
                -a, --auto-compress
                Use archive suffix to determine the compression program.

                -I, --use-compress-program=COMMAND
                Filter data through COMMAND. It must accept the -d option, for
                decompression. The argument can contain command line options.

                -j, --bzip2
                Filter the archive through bzip2(1).

                -J, --xz
                Filter the archive through xz(1).

                --lzip Filter the archive through lzip(1).

                --lzma Filter the archive through lzma(1).

                --lzop Filter the archive through lzop(1).

                --no-auto-compress
                Do not use archive suffix to determine the compression program.

                -z, --gzip, --gunzip, --ungzip
                Filter the archive through gzip(1).

                -Z, --compress, --uncompress
                Filter the archive through compress(1).




                And yes, you can watch compressed archives the same way.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 19 at 7:02









                sudodus

                22.7k32872




                22.7k32872






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • 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%2faskubuntu.com%2fquestions%2f1103018%2fgzip-2-files-into-one-file%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

                    數位音樂下載

                    When can things happen in Etherscan, such as the picture below?

                    格利澤436b