Kasun’s Blog

Kasun Indrasiri

  • Kasun Indrasiri

  • Info

    Department of CSE
    University of Moratuwa,
    Sri Lanka

  • Archives

  • Categories

GNU Zip – How to guide..

Posted by kasun04 on June 21, 2008

gzip (GNU zip) is a compression utility designed to be a replacement for compress. Its main advantages over compress are much better compression and freedom from patented algorithms. It has been adopted by the GNU project and is now relatively popular on the Internet.

gzip was written by Jean-loup Gailly , and Mark Adler for the decompression code. [http://www.gzip.org/]

gzip produces files with a .gz extension. gunzip can decompress files created by gzip, compress or pack. The detection of the input format is automatic.

How to extract a .tar.gz/.tgz file.

Extracting a .tar.gz file is one of the problem that encountered during the early days of working with linux. This is how you can do in a flash.

gunzip < your_file.tar.gz | tar xvf –

gunzip < your_file.tgz | tar xvf –

Create .tar.gz archive

Here is the magical way of doing this…

tar -pczf name_of_archive.tar.gz /destination_dir

To tar all .cc and .h files into a tar file named foo.tgz use:

Here is some more detailed version

    tar cvzf foo.tgz *.cc *.h

This creates (c) a compressed (z) tar file named foo.tgz (f) and shows the files being stored into the tar file (v). The .tgz suffix is a convention for gzipped tar files, it’s useful to use the convention since you’ll know to use z to restore/extract.

It’s often more useful to tar a directory (which tars all files and subdirectories recursively unless you specify otherwise). The nice part about tarring a directory is that it is untarred as a directory rather than as individual files.

   tar cvzf foo.tgz cps100

will tar the directory cps100 (and its files/subdirectories) into a tar file named foo.tgz.

To see a tar file’s table of contents use:

   tar tzf foo.tgz

To extract the contents of a tar file use:

    tar xvzf foo.tgz

This untars/extracts (x) into the directory from which the command is invoked, and prints the files being extracted (v).

If you want to untar into a specified directory, change into that directory and then use tar. For example, to untar into a directory named newdir:

   mkdir newdir
   cd newdir
   tar xvzf ../foo.tgz

You can extract only one (or several) files if you know the name of the file. For example, to extract the file named anagram.cc from the tarfile foo.tgz:

   tar xvzf foo.tgz anagram.cc



One Response to “GNU Zip – How to guide..”

  1. emadeCradE said

    Very nice!!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: