How to Extract Archives [tar|gz|bz2|rar|zip|7z|tbz2|tgz|Z]

Hello guys,

This is a practice blog post, where I am going to tell how to unpack and uncompress the most popular [tar|gz|bz2|rar|zip|7z|tgz|Z] types of archives from the Linux command line. You can see how to open many compressed file types following these steps.

You can open many compressed file by using the following commands. Use the following commands to extract TAR archives compressed with GZIP and BZIP2.

root# tar xvf file.tar
root# tar xvzf file.tar.gz
root# tar xvzf file.tar.tgz
root# tar xvjf file.tar.bz2
root# tar xvjf file.tar.tbz2  


Use the following commands to uncompress archives or files, compressed with
ZIP,GUNZIP, RAR, BUNZIP2, COMPRESS and 7Z programs. And the same with programs which can open the compressed files.

root# unzip file.zip
root# gunzip file.gz
root# unrar x file.rar
root# bunzip2 file.bz2
root# uncompress file.Z
root# 7z file.7z   


Extract Archives with Shell Script

I would strongly recommend you to use this script. You can open the compressed files with a single command. If you don’t have ~/.bashrc file, you can use this command ( touch ~/.bashrc ). If you have ~/.bashrc file, please, use bash shell function as it shown below( add to your ~/.bashrc).

NOTE : Supported file types : .zip, .rar, .bz2, .gz, .tar, .tbz2, .tgz, .Z, .7z, .xz, .exe, .tar.bz2, .tar.gz, .tar.xz.

function extract {
if [ -z "$1" ]; then
   # display usage if no parameters given
   echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
   if [ -f "$1" ] ; then
       NAME=${1%.*}
       #mkdir $NAME && cd $NAME
       case "$1" in
         *.tar.bz2)   tar xvjf ./"$1"    ;;
         *.tar.gz)    tar xvzf ./"$1"    ;;
         *.tar.xz)    tar xvJf ./"$1"    ;;
         *.lzma)      unlzma ./"$1"      ;;
         *.bz2)       bunzip2 ./"$1"     ;;
         *.rar)       unrar x -ad ./"$1" ;;
         *.gz)        gunzip ./"$1"      ;;
         *.tar)       tar xvf ./"$1"     ;;
         *.tbz2)      tar xvjf ./"$1"    ;;
         *.tgz)       tar xvzf ./"$1"    ;;
         *.zip)       unzip ./"$1"       ;;
         *.Z)         uncompress ./"$1"  ;;
         *.7z)        7z x ./"$1"        ;;
         *.xz)        unxz ./"$1"        ;;
         *.exe)       cabextract ./"$1"  ;;
         *)           echo "extract: '$1' - unknown archive method" ;;
       esac
   else
       echo "'$1' - file does not exist"
   fi
fi
}  


Source :
https://github.com/xvoland/Extract

Use the following command the reload .bashrc file. Don’t forget to put ( . ) point to mark the beginning of the command.  🙂

root# . ~ /.bashrc  

Now, using the following command, you can open supported file types.

root# extract file.rar
root# extract file.tar.gz2
root# extract file.tar
root# extract file.7z  

Turkish version here.

That’s it.

Tagged with: , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

five × 4 =

Archives

Tweets