Exploring Unix aliases

By Alvin J. Alexander, devdaily.com

I create aliases a lot when using Unix systems. Aliases are a real nice way of customizing the system to work the way you want it to work. I won't describe these too much, I'm just going to throw them out here. One thing I should note is that this syntax assumes you're using the Bash or Korn shells. I think the syntax is a little different with other shells, like csh, but I don't remember the syntax differences.

alias cd..="cd .."
alias cd...="cd ../.."
alias cd...="cd ../.."
alias gi="grep -i"
alias l="ls -al"
alias lm="ls -al | more"
alias lf="ls -FG"
alias h=history
alias hm="history | more"

# places:
alias bin="cd /Users/al/tomcat/bin"
alias html="cd /home/apache/html"

# file find:
alias ff="find . -type f -name "

# "que pasa" (an old friend said this a lot):
alias qp="ps auxwww | more"

# i modified this one for public consumption:
alias fb="ssh al@foo.bar.com"

# for dos users:
alias dir="ls -al"
alias md=mkdir
alias ren=mv
alias type=cat
alias search=grep

Hopefully most of those aliases are very straightforward. Note that any time you have spaces in your commands (to the right of the equal sign) you'll need to put quotes around your commands.

To use an alias, just type your alias, like this:

cd...

The system responds by replacing your alias with the actual command(s) the alias represents:

cd ../..

The weirdest alias I've shown may be ff, which I use like this:

ff some_file

which expands to this:

find . -type f -name some_file

Storing your aliases

If you create an alias from the command line it will last only as long as your login session lasts. When you log out, then back in again, your alias will be gone. To make your aliases available for future login sessions you'll want to store them in your .bash_profile or .profile files, which are read by the bash shell when a login session is started.


devdaily logo