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.
Preliminary:
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
tar xvf filename.tar
.tar.gz
tar xzvf filename.tar.gz
.tgz
tar xvzf filename.tgz
.tar.gz2
You probably mean .tar.bz2
.tar.bz
tar xjvf filename.tar.bz
.tbz
tar xjvf filename.tbz
.tar.bz2
tar xjvf filename.tar.bz2
.tar.Z
zcat file.tar.Z | tar xvf -
.tar.xz
lzcat filename.tar.xz | tar xvf -
.gz
gunzip filename.gz
.gz2
You probably mean .bz2
.bz
bunzip filename.bz
.bz2
bunzip2 filename.bz2
.Z
uncompress filename.Z
.xz
unlzma filename.xz
.zip
unzip filename.zip
.7z
7z x filename.7z
.rar
unrar e filename.rar
.dmg
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/
.img, .dd
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/
.more?
Have more to share? I wouldn’t mind hearing about it in the comments if you do!
.trouble?
Let me know about it in the comments. We’ll get it straightened out.
.notes
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.
Feel free to
buy me a soda if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that I hope you'll be interested in:
Here are some similar posts that you may be interested in:
- Create/Compress/Archive Almost Any File in Linux (tar, tar.gz, tar.bz2, gz, bz, zip, 7z, rar, etc…)
- Writing a .dd.bz2 Image Directly to Media
- How-To: Setup a Pre-Built VirtualBox Guest Image [Tutorial/Guide]
- Including a Program Source File in LaTeX [Tip]
- Debug with ‘tail -f dmesg’ Equivalent and ‘proc/sys/kernel/printk’ Logging