Create/Compress/Archive Almost Any File in Linux (tar, tar.gz, tar.bz2, gz, bz, zip, 7z, rar, etc…)

This is a no-frills Linux command line guide/cheat sheet that will help you archive or compress just about any file that you’re bound to come across. If you’d like to have more options, read the man pages! Also, the opposite to this guide about extracting/uncompressing/unarchiving files in Linux can be found here.


Most compression or archiving methods that you may want are already built into popular distributions (Ubuntu, Fedora, Suse, etc…), but some of them aren’t. I would recommend installing this group of packages using apt-get, yum, or an equivalent before using this guide (unless of course you already know what you need):

su -c 'yum install unzip zip p7zip rar unrar bzip2 gzip lzma'


tar cvf filename.tar /dir


tar czvf filename.tar.gz /dir


tar cvzf filename.tgz /dir


You probably mean .tar.bz2


tar cjvf filename.tar.bz /dir


tar cjvf filename.tbz /dir


tar cjvf filename.tar.bz2 /dir


.Z is an old naming convention which has moved to .gz.  See .tar.gz above.


tar cvf -  filenames | lzma > filename.tar.xz 


gzip filename


You probably mean .bz2


bzip filename


bzip2 filename


.Z is an old naming convention which has moved to .gz.  See .gz above.


lzma filename


zip -r filename.zip /dir


7z a -t7z filename.7z /dir


rar a filename.rar /dir


This is a bit more complicated than what I have time for. Looks like somebody has already figured something out.


Create these image files using:

dd if=inputfile.dd of=outputfile.dd


Have more to share? I wouldn’t mind hearing about it in the comments if you do!


Let me know about it in the comments. We’ll get it straightened out.

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:

There's 2 Comments So Far

  • bas
    December 8th, 2012 at 2:00 am

    How can i create an Archive WinRar compatible with Tar?
    I know i have to install a tar “extention” by command line… which command?
    ap-get install tar-winrar??

Who Linked To This Post?

  1. How To: Get .rar Support in Fedora 13 [Two-Liner Command] | The Linux Daily

Share your thoughts, leave a comment!