Useful bash aliases and generating a listing of your most used commands

I deal with a lot of different machines so one of my favorites is aliases for each machine that I need to frequently SSH to:

alias claudius="ssh dinomite@claudius"

It is also useful to setup a good .ssh/config and ssh keys to make hopping amongst machines even easier.

Another one of my favorite aliases is for moving up directories:

alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."

And some for commonly used variations of ls (and typos):

alias ll="ls -l"
alias lo="ls -o"alias lh="ls -lh"
alias la="ls -la"
alias sl="ls"
alias l="ls"
alias s="ls"

I almost always want egrep:

alias grep="egrep"

Get man pages from all sections

alias man="man -a"

I often found myself piping output through awk in order to get a certain column of the output, as in df -h | awk '{print $2}' to find the size of each of my disks. To make this easier, I created a function fawk in my .bashrc:

function fawk {
    first="awk '{print "
    last="}'"
    cmd="${first}\$${1}${last}"
    eval $cmd
}

I can now run df -h|fawk 2 which saves a good bit of typing.

I work with a lot of Perl and need to know the versions of modules installed on a system:

function perlmodver {
    perl -M$1 -e 'print "Version " .
        $ARGV[0]->VERSION . " of " . $ARGV[0] .
        " is installed.\n"' $1
}

I usually like to type everything, because I'm afraid I'll forget all about the commands I'm using in no time. I know I may be wrong, but I don't think I'd know as much about the system if I had just pasted every command in Commandlinefu into my .bashrc.

Note that I'm not saying that I'm the greatest and I know everything there is to know about Linux, far from that, I'm just saying I like to learn, and remember what I've learned by using.

That's not to say I don't appreciate how time saving aliases are (specially for larger functions, but then you have to see if a script isn't better), but, personally, I don't like to use them (at least no always).

That being said, Commandlinefu has a special tag for aliases. It's worth looking.

Also I think this is a good one:

   alias less='less -FSRX'

This will only use less if the output is bigger than the screen.


My favorite of all times:

alias server_name='ssh -v -l username ip_address'

It doesn't need explanation, does it? :-)


alias lt='ls -lhart'

  • l=long : h=human readable sizes : a=all : r=reverse sort : t=time sort
  • Puts the newest file at the bottom, right above the prompt

alias active='grep -v -e "^$" -e"^ *#"'

  • shows only lines that are not blank or commented out
  • example: active /etc/httpd/conf/httpd.conf

alias svi='sudo vim'

alias scr='screen -Rd'