transmission line noise

home

Brer Rab­bit and Taring

06 Feb 2011

Tagged with Machine Utilities, Work

TAR

Tar is a very com­monly used archiv­ing for­mat on Linux sys­tems. The advan­tage with tar is that it con­sumes very lit­tle time and CPU to com­press files, but the com­pres­sion isn’t very much either. Tar is prob­a­bly the Linux/UNIX ver­sion of zip – quick and dirty. Here’s how you com­press a directory:

 tar –cvf archive_name.tar directory_to_compress

And to extract the archive:

 tar –xvf archive_name.tar.gz

This will extract the files in the archive_name.tar archive in the cur­rent direc­tory. Like with the tar for­mat you can option­ally extract the files to a dif­fer­ent directory:

 tar –xvf archive_name.tar –C /tmp/extract_here/

TAR.GZ

This for­mat is my weapon of choice for most com­pres­sion. It gives very good com­pres­sion while not uti­liz­ing too much of the CPU while it is com­press­ing the data. To com­press a direc­tory use the fol­low­ing syntax:

 tar –zcvf archive_name.tar.gz directory_to_compress

To decom­press an archive use the fol­low­ing syntax:

 tar –zxvf archive_name.tar.gz

This will extract the files in the archive_name.tar.gz archive in the cur­rent direc­tory. Like with the tar for­mat you can option­ally extract the files to a dif­fer­ent directory:

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

TAR.BZ2

This for­mat has the best level of com­pres­sion among all of the for­mats I’ve men­tioned here. But this comes at a cost – in time and in CPU. Here’s how you com­press a direc­tory 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 cur­rent direc­tory. To extract the files to a dif­fer­ent direc­tory use:

 tar –jxvf archive_name.tar.bz2 –C /tmp/extract_here/

Data com­pres­sion is very handy par­tic­u­larly for back­ups. So if you have a shell script that takes a backup of your files on a reg­u­lar basis you should think about using one of the com­pres­sion for­mats you learned about here to shrink your backup size.

Over time you will real­ize that there is a trade-off between the level of com­pres­sion and the the time and CPU taken to com­press. You will learn to judge where you need a quick but less effec­tive com­pres­sion, and when you need the com­pres­sion to be of a high level and you can afford to wait a lit­tle while longer.

From Sim­ple­help

comments powered by Disqus