next up previous
Next: Shells Up: Introduction to the Linux Previous: Managing jobs

Aliases

Sometimes we find ourselves using commands with the same set of options over and over again, or laboriously typing the same set of commands may times. We can avoid this by using aliases.

A simple, but useful, example is the rm command. By default this removes a file without any questions being asked, but we might prefer it to check that we really want to remove each file. Looking at the man page you can see that we want rm -i. We could make sure that this was the default by setting up and alias:

[phasnip@mijpnb1 ~]$ alias rm rm -i
[phasnip@mijpnb1 ~]$ rm junk
rm: remove `junk'? yes

The first argument is what we want to call the alias, and the second is what we want it to do. Typing alias without any arguments lists the aliases that have been set, and typing it with an existing alias name will show the definition of that alias. To remove an alias just use the unalias command.

[phasnip@mijpnb1 ~]$ alias
ls      ls --color=tty
rm      (rm -i)

When you set an alias it is only set in the current terminal window on the current computer, it will not propagate to any other terminal windows you may have open or that you open subsequently. To make sure this alias was always set, you would have to put it into one of your configuration files.


next up previous
Next: Shells Up: Introduction to the Linux Previous: Managing jobs
Phil Hasnip 2007-08-23