The life of those managing Linux instances is a bit complicated so let’s make it a bit easier. Sometimes it’s a pain to repeat the same long command over and over. In order to avoid that we are going to create shortcuts for commands by using aliases.
Everything looks better with color so let’s add some to the ls output:
alias ls='ls --color=auto'
I’m also using an alias for the long listing format. This one is very common and a MUST have:
alias ll='ls -la'
In order to show hidden files (with color) use:
alias l.='ls -d .* --color=auto'
We all hate typos so let’s make an alias to get rid of the most common typo: ‘cd..’
alias cd..='cd ..'
Get a quick way to get out of the current directory:
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../..'
More color! This time for the grep/egrep/fgrep command. This may be useful when doing grep for big files:
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
Let’s go for a few useful aliases for common commands for history, jobs, ports info, memory info and cpu info:
alias j='jobs -l'
alias ports='netstat -tulanp'
alias meminfo='free -m -l -t'
Get the top memory consuming process:
alias psmem='ps auxf | sort -nr -k 4'
Get the top cpu consuming process:
alias pscpu='ps auxf | sort -nr -k 3'
I add the aliases in ~/.bashrc so all the aliases will load every time that used bash as the shell. Do you also use aliases? please share with us your favorite aliases on Twitter or in the comments below.
If you enjoyed the read, drop us a comment below or share the article, follow us on Twitter or subscribe to our #MetaBeers newsletter. Before you go, grab a PDF of the article, and let us know if it’s time we worked together.