How to compress a tar file in linux?

Quick example to show you how to zip / compress and unzip / uncompress a tar file in linux. First, you need to know what’re the available options in of tar command.

man tar 

or

tar --help

Following are 5 commonly used options – c, z, f, v, x

  • c = create a new tar file
  • v = verbose , display file to compress or uncompress
  • f = create the tar file with filename provided as the argument
  • z = use gzip to zip it
  • x = extract file

1. Compress / Zip

Compress / zip it with command tar -cvzf new_tarname.tar.gz folder-you-want-to-compress

In this example, compress a folder named “scheduler”, into a new tar file “scheduler.tar.gz”.

$ tar -cvzf scheduler.tar.gz scheduler

2. Uncompress / unizp

To UnCompress / unzip it, use this command tar -xzvf tarname-you-want-to-unzip.tar.gz

In this example, uncompress it or unzip above scheduler.tar.gz.

$ tar -xvzf scheduler.tar.gz

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
9 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
8 Comment authors
UnmilanEfren VenturaWouter GritterMasoudGagan Recent comment authors
newest oldest most voted
Wouter Gritter
Guest
Wouter Gritter

2. Uncompress / unizp
unzip is mistyped ;)

Unmilan
Guest
Unmilan

Thanks Mykong for preparing such a nice command

Efren Ventura
Guest
Efren Ventura

Great!! Excellent and very helpful

Masoud
Guest
Masoud

Very Very Tanks

Gagan
Guest
Gagan

Really very good and simple way to tell commands. Excellent!

sreenivas
Guest
sreenivas

thanks

Jass
Guest
Jass

Neat and simple! Thanks..

Huyu
Guest
Huyu

Nice and simple

trackback
How to install Apache Archiva in Ubuntu | Web Development

[…] More detail about tar command […]