Alias Command

The alias command is one of many commands referred to as Bash Built-In commands, meaning it is inherent to the bash shell and does not rely on an external program. Alias is used in many ways, but perhaps its most frequent use is that of shortening the number of keystrokes required at the command line to perform a given task.

Lets look at the following example, a simple directory listing, consisting of the ls command, followed by a number of options to the command.

ls -lvh

This outputs the directory listing to your screen, such as:

drwxrwxr-x 2 rickn rickn 4.0K Mar 18 11:25 bin

Nothing new there, however with alias we can shorten the number of keystrokes needed to accomplish this task very easily, simply enter something similar to the following:

alias lvh=’ls -lvh’

Now type the following command:

lvh

As you can see the output of the command is the same as before, it just took fewer keystrokes to get there. Alias takes the command string of ls -lvh and makes it accessible through the lvh alias. The alias name can be anything you want assuming there is not a command available which already uses the name you choose. Welcome to the beauty of the alias command. The aliases which have been defined are user specific so keep that in mind, also, if you ever need to see what aliases exist for a given user, just issue the following command logged in as that user:

alias

Good Luck !

Leave a Reply