Two Commands To Make You A Better Sysadmin

by Benson Wong

Great sysadmins use aliases to avoid repeatedly typing common commands. Everybody knows lazy sysadmins are the best ones.

The Commands:

alias a='cat ~/.bash_aliases'
alias ea='vi ~/.bash_aliases; echo "Refreshing aliases"; source ~/.bash_aliases'

Here’s what they do:

  1. the command ‘a’ now prints out a list of your current aliases
  2. the command ‘ea’ brings up vi to edit your aliases and refreshes them when you’re done

Here’s the work flow:

> ea
... edit edit hack hack
> a
... list of aliases ...

Where to put it:

Using Linux: ~/.bash_aliases. This file gets read when you log in.

If you are using a Mac do this. In ~/.bash_profile add:

source ~/.bash_aliases

Then add everything into that file instead.

Here’s what mine looks like (well a part of it):

unalias -a
alias a='cat ~/.bash_aliases'
alias ea='vi ~/.bash_aliases; echo "Refeshing aliases..."; source ~/.bash_aliases'

# back up the day's work
alias bkup='sudo -i /root/backup.sh'

# ubuntu version
alias uver='cat /etc/lsb-release'

# manage apache configs
alias s='sudo vi /etc/apache2/sites-available/combined.conf'
alias sr='sudo /etc/init.d/apache2 reload'

# git short cuts
alias gb='git branch';
alias gs='git status';
alias gl='git log'
alias gsr='git svn rebase';
alias gsd='git svn dcommit';

# misc short cuts
alias ll='ls -l'
alias zf='zf.sh'
alias vi='vim'

Now go do it!

{ 2 comments… read them below or add one }

1 Jeff April 24, 2010 at 11:20 am

For extra bonus points, create a git repo with your aliases files and other scripts and check out the git repo on any machine you regularly log into, eg in ~/profile/… Then all you need to add to .bashrc / .profile / .bash_profile is:


if [ -f $HOME/profile/aliases ]; then
source $HOME/profile/aliases
fi

Reply

2 Daniel August 10, 2011 at 8:12 am

I use aliases all the time and manually refresh them. This script is a great idea, thanks. I wonder if there’s a way to get all your windows (in say, gnu screen manager) to refresh? Maybe refresh in the background every minute if a change is detected? Getting crazy now… Also thanks for the video on usb video adapters with your mbp.

Reply

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: