To be or not to be

May 21, 2008

How to tar and untar files in UNIX?

Filed under: How To, Shell Script — Tags: , , , , , — tdas @ 3:14 am

Few years ago, during my undergraduate degree, I was asked to compress my assignment using tar and submit it. I was so scared with all the tar+compress+unix jig, that I ended up NOT submitting the assignment :O. Now when I look back, I feel so stupid. Anyways, now that I know a lil bit more about tar and untar, I’d like to share my knowledge with everyone and hopefully help someone from NOT submitting an assignment 😛

Basically tar can be used to group multiple files/directories into one single file, and separate(extract) an archive created by tar into separate files.

* To group multiple files : tar -cvf foo.tar a.dat b.dat c.dat ( this will group files [a-c]*.dat to one file foo.tar )
c = create a tar file
v = verbose( nothing important 😛 )
f = create the tar file with filename provided as the argument

Thats all you need to know to tar(group) a bunch of files/directories.

* To tar files and gzip them : tar -czf foo.tar.gz *.dat ( this will create a gzip-compressed Tar file of the name foo.tar.gz of all files with a .dat suffix in that directory )

* To untar(separate) files from a tar archive : tar -xvf foo.tar ( this will produce three separate files a.dat, b.dat and c.dat )

* To untar(extract) a gzipped tar archive file : tar -xzf foo.tar.gz

* To untar a bzipped (.bz2) tar archive file : tar -xjf foo.tar.bz2



  1. Cool. Thx. 🙂

    Comment by sandeep — October 13, 2008 @ 4:25 pm

  2. […] How to tar and untar files in UNIX?, 2,321 views […]

    Pingback by stat « To be or not to be — October 20, 2008 @ 9:55 pm

  3. Hey that was helpful.I had another question can we untar a single file from the tarred ones.Also can we untar the files in the directory of our choice.

    Comment by Ajit Gunge — January 14, 2009 @ 6:10 am

  4. Thanks. Was just looking for this!

    Comment by — November 3, 2010 @ 11:05 am

  5. Thanks man

    Comment by pradeep — February 3, 2012 @ 10:07 am

RSS feed for comments on this post. TrackBack URI

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

Blog at

%d bloggers like this: