Solaris Advanced User's Guide

Command Aliases

Command aliases are helpful shortcuts for commands you often type. For example, the default setting for the remove command (rm) does not ask for confirmation before it removes files. Sometimes this default is inconvenient, as a typing error can remove the wrong file. However, you can use the alias variable to change this setting by editing your user profile file.

In the C and TC shells, add the following line to your user profile file.


alias rm  'rm -i'

In the Bourne Again, Korn, and Z shells, add the following line to your user profile file.


alias rm='rm -i'

With this line in your user profile file, typing rm is now the same as typing rm -i, which is the interactive form of the rm command. You will then always be asked to confirm the command before any files are deleted. The quote marks around rm -i in the previous example are necessary to include the blank space between rm and -i. Without the quotation marks, the shell cannot correctly interpret the text after the space.

To make your changes to your user profile file effective immediately in your current window, you need to type an additional command. In the C and TC shells, type the following command to make your alias effective immediately.


example% source user-profile-file

The source command causes the system to read the current user profile file and execute the commands in this file.

In the Bourne Again, Korn, and Z shells, type the following command to make your alias effective immediately.


$ . user-profile-file

In the Bourne Again, Korn, and Z shells, the . command performs the same actions as the source command in the C and TC shells.


Note –

Command aliases that are created by using the alias command apply only to the current session.