Absolutely Tech

[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 ~/.bashrc

Copy 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

Read the rest of this entry »

Extracting and adding files from and to Rar and 7z files

For Rar files:

My friend sent me a link to a rar file just today. After downloading, I found that rar file wasn’t supported natively on Ubuntu. I tried different softwares but none was good. So finally I installed rar and unrar, both of them aren’t free. They provide integration with the native gnome archive manager.
To install them, type the following line in terminal and press enter:

sudo apt-get install rar unrar

When you double click a rar file it will automatically open with gnome archive manager (file roller). Also, you’ll be able to see the rar format option available in the create archive dialog box.

For 7z files:

I also wanted to have 7z support while I was at this. So I just installed p7zip-full for this. It also provided integration with default archiver of gnome. To install it, type the following in terminal:

sudo apt-get install p7zip-full

This will give 7z support. Try double clicking a 7z file and it will open directly in archive manager. You will also find the option to select 7z in create archive dialog box.

Cheers!