Command line snippet of the week: 50

Forget that your running as underprivileged? No need to retype the command:

> command_with_insufficient_permissions
Permission denied

sudo !!

The !! parameter repeats the previous command, thus no need to retype!

Source: shell-fu

divider

Command line snippet of the week: 49

Want to show something on your machine to someone over the web? Don’t copy it or upload it somewhere, try this command (requires Python):

alias webshare='python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"'

Just run “webshare” and the current directory and everything beneath it will be served from a new web server listening on port 8000. When you are finished, just hit control-c to close the webserver.

divider

Command line snippet of the week: 48

Hate having to remember all switches for each different unpacker? You can fix that!
Create a new file in /usr/bin/ called “extract” and paste the following code:

if [ -f $1 ] ; then
case $1 in
    *.tar.bz2)   tar xvjf $1        ;;
    *.tar.gz)    tar xvzf $1     ;;
    *.bz2)       bunzip2 $1       ;;
    *.rar)       unrar x $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    ;;
    *)           echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi

be sure to chmod it to executable:

chmod +x /usr/bin/extract

This code will save you time by extracting almost any kind of archive by using the command:

extract my_awesome_archive.tar.gz
divider