Thursday, 5 July 2012

Compressing and zipping a directory in UNIX.

I got a requirement of compressing and zipping a directory. Searched for it and found it at last. Let me discuss what I learned. When I started learning I got a clue that it can be compressed by Gzip. It dint satisfy my requirement.
                gzip {filename}   eg: gzip mydata.doc
Gzip compress the size of the given files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz.
To Zip and compress my directory I used tar utility at the end. Let me give the description of this utility,   The GNU tar is archiving utility but it can be use to compressing large file(s). GNU tar supports archive compressing through gzip. If you have more than 2 files then it is recommended to use tar instead of gzip.
-z: use gzip compress
Syntax and example for tar along with gzip utility
tar -zcvf {.tgz-file} {files}      eg :tar –zcvf myfile.tar.gz –c /tmp/myfile

No comments:

Post a Comment