|Lesson 2||Creating aliases|
|Objective||Create command shortcuts using the alias command. |
Create Command Shortcuts using Unix Alias Command
Aliases let you define abbreviations for often-used commands. Aliases are a feature of the C shell (and a few others, such as the Korn shell
. I will describe the C shell syntax. The following command is used to create an alias:
% alias name command
The most basic aliases define a new name for a simple command:
% alias dir ls
This command renames the ls command as dir. From now on, when you type dir, it is the same as typing
ls. That is handy if you are used to DOS, where dir is the command to list files.
Aliases let you run commands with specific options. For example, the table below shows two ways you can define an alias:
| Alias || Description |
| alias ll ls l || List files in long format. |
| alias p1 lp -dHP400 || Send files to printer HP400. |
In the first example, the ll alias saves you from typing ls -l. And instead of trying to remember a printer named
HP400, you can create an alias to the lp command.
Aliases also let you redefine existing commands to make them easier to use. Some examples are:
% alias cp cp -i
% alias mv mv -i
% alias rm rm -i
Once in place, these commands automatically prompt you before overwriting or removing a file.
You no longer need to specify the -i yourself.
If you use an alias to redefine a command, the original command is no longer available.
The next lesson will present a way around this.
When creating alias definitions, it is sometimes necessary to use quotes
In the next lesson, listing and disabling aliases will be discussed.
The Korn shell is a commonly used UNIX shell. It is a superset of the Bourne shell, and in the command line offers conveniences similar to those of the C shell.