Saturday, September 11, 2010

How to Extract/Uncompress/Unarchive file in linux.

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):

[root@localhost]# yum install -y unzip p7zip unrar bzip2 gzip lzma

1. *.tar
[root@localhost]# tar xvf filename.tar

2. *.tar.gz
[root@localhost]# tar xzvf filename.tar.gz

3. *.tgz
[root@localhost]# tar xvzf filename.tgz

4. *.tar.bz2 (Or maybe we mean *.tar.gz2)
[root@localhost]# tar xjvf filename.tar.bz2

5. *
[root@localhost]# tar xjvf

6. *.tbz
[root@localhost]# tar xjvf filename.tbz

7. *.tar.Z
[root@localhost]# zcat file.tar.Z | tar xvf -

8. *.tar.xz
[root@localhost]# lzcat filename.tar.xz | tar xvf -

9. *.gz
[root@localhost]# gunzip filename.gz

10. *.gz2 (Or maybe we mean *.bz2. It's the same way like untar *.bz2 above)

11. *.bz
[root@localhost]# bunzip

12. *.bz2
[root@localhost]# bunzip2 filename.bz2

13. *.Z
[root@localhost]# uncompress filename.Z

14. *.xz
[root@localhost]# unlzma filename.xz

15. *.zip
[root@localhost]# unzip

16. *.7z
[root@localhost]# 7z x filename.7z

17. *.rar
[root@localhost]# unrar x filename.rar

18 *.dmg
This isn’t a file that can be ‘extracted’ but you can mount and save the files using:
[root@localhost]# mkdir /mnt/source
[root@localhost]# mount -o loop -t hfs filename.dmg /mnt/source
[root@localhost]# cp /mnt/source/* /home/username/destination/

19. *.img, *.dd
These aren’t files that can be ‘extracted’ but you can mount and save the files using:
[root@localhost]# mkdir /mnt/source
[root@localhost]# mount -o loop -t iso9660 filename.img /mnt/source
[root@localhost]# cp /mnt/source/* /home/username/destination/

NOTES: "*" means to your filename which will to unpack. Example "testsource-12.1.0-1.tar.gz".
Read more "How to Extract/Uncompress/Unarchive file in linux...."

Linux Documentation ©  Copyright by Parapat Notes | Asterisk Telephony | OpenSource Distribution Source Developer