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"
History can be very useful, but by default on most distributions your history is blown away by each shell exiting, and it doesn't hold much to begin with. I like to have 10,000 lines of history:
export HISTFILESIZE=20000
export HISTSIZE=10000
shopt -s histappend
# Combine multiline commands into one in history
shopt -s cmdhist
# Ignore duplicates, ls without options and builtin commands
HISTCONTROL=ignoredups
export HISTIGNORE="&:ls:[bf]g:exit"
That way, if I know that I've done something before but can't remember the specifics, a quick history | grep foo
will help jog my memory.
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.
If you need to specify a delimiter (e.g., awk -F:
for /etc/passwd
), this function obviously can't handle that. The slightly-overhauled version in this gist can handle arbitrary awk
arguments before the field number (but still requires input from stdin).