SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: what is Linux command for compressing the contents of a Directory?

Hybrid View

  1. #1
    SitePoint Guru WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    984
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    what is Linux command for compressing the contents of a Directory?

    Hello,

    What is Linux command for compressing all the files under a Directory, as
    well as all the files in sub-directories under that directory, so that upon
    uncompression the files are created in the right directory and sub-directory.

    Also of course what is the command to un-compress this compressed file?

    In case: the Linux OS here is Redhat Enterprise and the web server is Apache.

    Regards,

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use tar, or gzip, or zip... those are commonly included packages in major distributions. There are other compression utilities available too.

    To learn how to use the package, consult the manual.

    Type "man tar" or "man gzip" or "man zip".

  3. #3
    SitePoint Guru WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    984
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Could you kindly tell me what is the exact command for this task?
    I really do not have the time to read man instructions which are very
    cryptic at best and given the importance of this task, do not want
    to task mis-reading it.

    Regards,

    Quote Originally Posted by Dan Grossman View Post
    Use tar, or gzip, or zip... those are commonly included packages in major distributions. There are other compression utilities available too.

    To learn how to use the package, consult the manual.

    Type "man tar" or "man gzip" or "man zip".

    Anoox search engine volunteer

    www.anoox.com

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    SitePoint Guru WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    984
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    1st, thanx for your quick reply.

    2nd, it does not work. That is after issuing the command
    tar -cvf main_backup_Oct1309.tar ROOT/
    where Root is the directory below where I am now which contains many
    files and subdirectories, then I instantly get the file main_backup_Oct1309.tar
    which is only 10240 KB which cannot be right since there are like 2000 files
    under that directory.

    3rd, what is the command for unpacking the tar files generated by this
    compressions command?

    Regards,

    Quote Originally Posted by Dan Grossman View Post

    Anoox search engine volunteer

    www.anoox.com

  6. #6
    SitePoint Zealot cpace1983's Avatar
    Join Date
    Sep 2009
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tar -cvf tarfile.tar /location/to/backup

    is correct.

    tar -xvf tarfile.tar

    will extract it.

    du -h /path

    will tell you how large the directory is that you are backing up.
    I am a Freelance Linux Consultant.
    I offer flat rate Linux support, as well as hourly support.
    Feel free to visit my blog, Ramblings of a Linux Administrator.

  7. #7
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Add in the -z flag to add gzip compression and you'll get an even smaller file out

  8. #8
    SitePoint Guru WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    984
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I figured out what I was doing wrong.
    I was issuing the compression command, that is:
    tar -cvf backupfile.tar xyz.com/

    from a sym linked (aliased) location of that directory and not from the
    actual psychical location of that directory. Once I CDed to the actual
    location of that dir and issued the compression command then it was Ok
    and the resulting tar file is 1.5GB.

    You know I had this realization about what I was doing wrong while
    walking in a cold snow falling here in Vienna (Austria) so all of a sudden
    I kind of pumped my fist Eurika, and these Austrians are very stuffy, so I kind of stood out

    Ich wünsche alles eine sehr Guten Tag and Nacht





    Quote Originally Posted by Dan Grossman View Post
    Add in the -z flag to add gzip compression and you'll get an even smaller file out

    Anoox search engine volunteer

    www.anoox.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •