Useful shell aliases

Redo the last command as if I had sudoed

alias please='sudo $(fc -ln -1)'

Use this all the time

(Ubuntu) Install a package I don’t have but tried to use

alias ok='eval $($(fc -ln -1) 2>&1 | sed -n 2p)'

Go back to previous directory

alias back='cd $OLDPWD'

I use this one most of all when copying files to destinations outside of the current directory, especially if the paths involved are pretty long. Sometimes after copying, I may follow the file to the destination just to check what I just did by changing directory to the destination directory. ‘back’ lets me return to where I was before pretty effortlessly. This alias takes advantage of the OLDPWD environment variable.

Free up system memory

alias freemem='echo "echo 1 > /proc/sys/vm/drop_caches" | sudo sh'

For this example, I started to copy a 4 GB file so that I knew my ram would start to be used up. Here, you can see my memory available on the left is decreasing as I hit enter for purposes of demonstration. (displaying my system memory is done using the PROMPT_COMMAND environment variable). You can see when I use freemem, I get my memory back.

Colorize cat!

alias dog='pygmentize -g'

This works like cat in that it dumps the contents of a file to the screen. It does not concatenate files. But it does read the shebang and print the code with syntax highlighting, if it can. Requires python-pygmentize

Find a file or directory in working dir matching a string.

I use this one a LOT! Ignores case and prints line number.

alias lsg='ls -la| grep -ni'

I have many variants of this one, most notably to do this recursively through directories beneath you: ls -laR | grep -in

If you don’t have pygmentize for my dog alias, make installing it a breeze

(Ubuntu) obviously

alias gimme='sudo apt-get install'

Hexadecimal word games. Not fail = foresee!

If you write “fail” as 0x0FA11, not fail becomes 0xF05EE..or “foresee!”

It’s fun to try and write words in hex, like “deadbeef” of “cafebabe.” If we allow ourselves certain 1337 notations for letters, we can write even more words as Hexadecimal integers like “5ca1ab1e.” Pretty cool!

What is not scalable? Well that’s computable … not 0x5ca1ab1e is 0xa35e54e1. This isn’t a word.

But as I demonstrated above, much fun can be had by taking binary operations on these integers. Not fail is foresee. Can you find any others?