Extract/Uncompress/Unarchive 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 extract or unarchive or uncompress 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 creating/compressing/archiving files in Linux can be found here.
Most compressed or archived files that you’ll come across already have built-in support under 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 p7zip unrar bzip2 gzip lzma'
tar xvf filename.tar
tar xzvf filename.tar.gz
tar xvzf filename.tgz
You probably mean .tar.bz2
tar xjvf filename.tar.bz
tar xjvf filename.tbz
tar xjvf filename.tar.bz2
zcat file.tar.Z | tar xvf -
lzcat filename.tar.xz | tar xvf -
You probably mean .bz2
7z x filename.7z
unrar x filename.rar
This isn’t a file that can be ‘extracted’ but you can mount and save the files using:
mkdir /mnt/source mount -o loop -t hfs filename.dmg /mnt/source cp /mnt/source/* /home/username/destination/
These aren’t files that can be ‘extracted’ but you can mount and save the files using:
mkdir /mnt/source mount -o loop -t iso9660 filename.img /mnt/source cp /mnt/source/* /home/username/destination/
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.
Apparently with newer versions of tar, you don’t need to specify the j or z options when dealing with .tar.xxx files, but I’m still going to include them here just in case there are users out there using an older version still.