Jump to Navigation

178 - zip, tar compress utilities

1. zip

Zip is probably the most commonly used archiving format out there today. Its biggest advantage is the fact that it is available on all operating system
platforms such as Linux, Windows, and Mac OS, and generally supported out of the box. The downside of the zip format is that it does not offer
the best level of compression. Tar.gz and tar.bz2 are far superior in that respect. Let’s move on to usage now.

To compress a directory with zip do the following :

# zip -r archive_name.zip <directory_to_compress>

Here’s how you extract a zip archive :

# unzip archive_name.zip

2. tar

Tar is a very commonly used archiving format on Linux systems. The advantage with tar is that it consumes very little time and CPU to compress files,
but the compression isn’t very much either. Tar is probably the Linux/UNIX version of zip.

Here’s how you compress a directory :

# tar -cvf archive_name.tar directory_to_compress

And to extract the archive :

# tar -xvf archive_name.tar.gz

To extract one file :

# tar xzvf mybkup.tar.gz my_project/test_dir/06-13-11/test01.xls

This will extract the files in the archive_name.tar archive in the current directory.
Like with the tar format you can optionally extract the files to a different directory :

# tar -xvf archive_name.tar -C /tmp/extract_here/

3. TAR.GZ

This format is my weapon of choice for most compression. It gives very good compression while not utilizing too much of the CPU while it is compressing
the data.

To compress a directory use the following syntax :

# tar -zcvf archive_name.tar.gz directory_to_compress

The following utilize much cpu and takes a long time(tripled) to be completed :

# tar -cvf - ./mydir | gzip -9 > /bkup/mydir.tar.gz

To decompress an archive use the following syntax :

# tar -zxvf archive_name.tar.gz

This will extract the files in the archive_name.tar.gz archive in the current directory. Like with the tar format you can optionally
extract the files to a different directory :

tar -zxvf archive_name.tar.gz -C /tmp/extract_here/

4. TAR.BZ2

This format has the best level of compression among all of the formats I’ve mentioned here. But this comes at a cost in time and in CPU.

Here’s how you compress a directory using tar.bz2 :

# tar -jcvf archive_name.tar.bz2 directory_to_compress

This will extract the files in the archive_name.tar.bz2 archive in the current directory.

To extract the files to a different directory use :

# tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/

 

Linux:


Main menu 2

Story | by Dr. Radut