Creating a .gz for a directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trs204
    New Member
    • Feb 2007
    • 12

    #1

    Creating a .gz for a directory

    Another newbie question...

    I searched the internet couple of hours... I pity myself... for not being able to find a command for making .gz file for a directory.
    I found only : gzip -c filename.txt
    which creates a gz for a single file.. but I am in need of a command for a directory containing files/directories.

    please advise. thx in advance.
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by trs204
    Another newbie question...

    I searched the internet couple of hours... I pity myself... for not being able to find a command for making .gz file for a directory.
    I found only : gzip -c filename.txt
    which creates a gz for a single file.. but I am in need of a command for a directory containing files/directories.

    please advise. thx in advance.
    Gzip, by design, is used to compress single files. The traditional method for creatinga compressed directory, is by using the TAR utility, with compression enabled:
    Code:
    # tar -czvf directory.tar.gz directory/

    Comment

    • trs204
      New Member
      • Feb 2007
      • 12

      #3
      my requirement says... somebody going to provide me gz and tar.gz both types containing multiple files...

      To uncompress... I found the commands:
      1) gunzip file.gz ( not sure how to make a sample to test this)
      2) tar zxvf file.tar.gz ( able to test this by creating a tar and compressing it)

      but as you mentioned... as per the design only file can be compressed... nto the directory... do you mean that they cant the provide me a .gz file, which contains multiple normal files/directories.

      thx in advance.

      Comment

      • ghostdog74
        Recognized Expert Contributor
        • Apr 2006
        • 511

        #4
        Originally posted by trs204
        my requirement says... somebody going to provide me gz and tar.gz both types containing multiple files...

        To uncompress... I found the commands:
        1) gunzip file.gz ( not sure how to make a sample to test this)
        2) tar zxvf file.tar.gz ( able to test this by creating a tar and compressing it)

        but as you mentioned... as per the design only file can be compressed... nto the directory... do you mean that they cant the provide me a .gz file, which contains multiple normal files/directories.

        thx in advance.
        theoretically speaking, it can be done without using tar. say you have 2 files, file1 and file2 you need to compress together
        Code:
        cat file1 file2  | gzip > together.gz # compress 2 files into single
        gunzip -c together.gz  # this is same as cat file1 file2
        but i think tar is still better.

        Comment

        • trs204
          New Member
          • Feb 2007
          • 12

          #5
          Thanks for the reply.. I was able to create the .gz file by specifying multiple files... but when I decompress it using this....
          gunzip filename.gz ==> this gave only one file.

          I think... cat does the concatenation of multiple files into a single file...

          But my situation... is... I am in need of a command that can zip a directory... that directory contains some directories and some files.... and want to retain the same directory structure when I am decompress it.

          Looks like they cannot provide me .gz file, which has multiple files and directories. .... is that my understanding seems right?

          Thx in advance.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Originally posted by trs204
            Thanks for the reply.. I was able to create the .gz file by specifying multiple files... but when I decompress it using this....
            gunzip filename.gz ==> this gave only one file.

            I think... cat does the concatenation of multiple files into a single file...

            But my situation... is... I am in need of a command that can zip a directory... that directory contains some directories and some files.... and want to retain the same directory structure when I am decompress it.

            Looks like they cannot provide me .gz file, which has multiple files and directories. .... is that my understanding seems right?

            Thx in advance.
            Not without using another utility such as tar.

            Comment

            • trs204
              New Member
              • Feb 2007
              • 12

              #7
              Thanks Motoma. And thank you all for making me comfortable on this.

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Originally posted by trs204
                Thanks Motoma. And thank you all for making me comfortable on this.
                You are welcome. Glad to help.

                If you figure out how this should (could) be done, post the result back here for us to see!

                Comment

                Working...