Posts tagged with: console

A bash script for Linux to extract all kind of compressed file from console.

Open ~/.bashrc file with your favorite editor and paste below script to the bottom of the file.

extract () {
if [ -f 1 ] ; then     case1 in
     *.tar.bz2) tar xvjf 1 ;;      *.tar.gz) tar xvzf1 ;;
     *.bz2) bunzip2 1 ;;      *.rar) rar x1 ;;
     *.gz) gunzip 1 ;;      *.tar) tar xvf1 ;;
     *.tbz2) tar xvjf 1 ;;      *.tgz) tar xvzf1 ;;
     *.zip) unzip 1 ;;      *.Z) uncompress1 ;;
     *.7z) 7z x 1 ;;     *) echo "don't know how to extract '1'..." ;;
   echo "'$1' is not a valid file!"

then write “extract” on console with the file you want to extract and see the effect.

extract bla.tar.gz

Some console commands on linux.

netstat -lpn | grep :8080

— it is combination of two commands with a pipe. It gives you the process that listens port 8080. It is really beneficial, if you’re dealing with some server things on linux.


mv <current name> <new name> or mv <current_location> <new_location>

–mv moves your folder or file to wherever you want as a second argument. Or you might use it to rename your file. (I’ve been using linux for three years and I did not know it up to now 🙂


gem list | cut -d” ” -f1 | xargs gem uninstall -aIx

–this is not a generic console command but it is really useful for rails developer especially for reinstalling all the rails and the gem files from the scratch. It removes all the gem files installed before.