Zip / Unzip / Tar Command (Linux)

I often end up getting zipped files which I supposed to crack open and look into.  Here are some tips working with compression in Linux.


[1]   Use -l option to see the files it contains.

$ unzip -l

[2]  -d  to unzip into a new directory.

$ unzip -d _RawData

To zip a directory recursively, use the -r option.

[3] zip -r _RawData

Note: looking at the sized, I found zip does quite a good job.

$ ls -lh
-rwxrwx—+ 1 agoswami Domain Users 109M Dec 16 13:10

$ ls -lh _RawData
total 1.2G

[4]  zipping up all folders containing word “azure” and their contents

zip -r *azure*

To zip urllib along with all azure folders, I do :

agoswami@agoswami-msft2 /cygdrive/c/Users/agoswami/AppData/Local/Continuum/Anaconda/Lib/site-packages
$ zip -r *azure* urllib3



Note : Because of various reasons some of which hearken back to the era of tape drives, Unix uses a program named tar to archive data, which can then be compressed with a compression program like gzipbzip27zip, etc

In order to “zip” a directory, the correct command would be

$ tar -zcvf _rawdata.tar.gz _RawData

$ ls -lh

-rwxrwxr–+ 1 agoswami Domain Users 109M Dec 16 15:43 _rawdata.tar.gz

This will tell tar to c (create) an archive from the files in directory (tar is recursive by default), compress it using the z (gzip) algorithm, store the output as a f (file) named archive.tar.gz, and v(verbosely) list all the files it adds to the archive.

To decompress and unpack the archive into the current directory you would use

tar -zxvf archive.tar.gz



gzip is a utility to compress / decompress individual files

$ ls -lh latency.txt
-rwxrwx—+ 1 agoswami Domain Users 3.0K Nov 22 20:07 latency.txt

$ ls -lh latency.txt.gz
-rwxrwx—+ 1 agoswami Domain Users 914 Nov 22 20:07 latency.txt.gz

to decompress : -d

$ gzip -d latency.txt.gz

to keep original file : -k

$ gzip -d -k rcv1.test.raw.txt.gz




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s