KEEP LIFE SIMPLE: USE ALIASES

Ever have a convoluted command that you ran often but hated typing out all of the time? Considering the command-line nature of Linux, the chances are likely that you have. There are two methods for dealing with the tedious nature of oft-used commands: You can write a shell script as a wrapper around the command, or you can use shell aliases. The script may seem fancier, but it can be more work than it's worth. Using an alias may be better suited to the situation.

Aliases are simple links to commands that the shell knows about. For instance, let's say you had to restart your Web server a number of times during the day for some reason and just didn't want to type the typical

/etc/rc.d/init.d/httpd restart

all of the time. You could instead create an alias by typing

alias httpd='/etc/rc.d/init.d/httpd'

This tells BASH that when it encounters the command httpd to execute /etc/rc.d/init.d/httpd instead, so you can then type

httpd restart

and get the same effect. You can do this with any command you want; aliases can be a good means of transition from the DOS command line to Linux by making aliases such as

alias dir='ls -l'

or

alias del='rm -i'

and so on. To make these changes permanent, simply add them to your ~/.bashrc file in your home directory. The ~/.bashrc is basically a shell script, so simply enter your aliases there as you would on the command line, and every time you open up a new console, your aliases will be available for you to use.