Jul 14, 2010 0
[HowTo]Extract almost any archive through terminal using a single command in linux
I came across this simple script on ubuntuforums which I thought was really very useful and worth sharing it on my blog. You can either make a function out of it and put it in .bashrc file or make an executable script and put it in /usr/bin/.
Method 1:
Open your ~/.bashrc file using any editor.
gedit ~/.bashrcCopy and paste the following code at the end of it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | extract-file () { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjvf $1 ;; *.tar.gz) tar xzvf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) rar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjvf $1 ;; *.tgz) tar xzvf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1 ;; *.7z) 7z x $1 ;; *) echo "'$1' cannot be extracted via extract-file" ;; esac else echo "'$1' is not a valid file" fi } |
Now you can use the following command to extract any archive:
extract-file
The command extract-file would be available only to terminals which have been opened after saving the .bashrc file with the above code. Also this code is user-specific, so if another user logs in he cannot use this command.
Method 2:
Use the following command to create a new file in /usr/bin directory and launch the gedit.
sudo gedit /usr/bin/extract-file
