Aliases allow you to use a command in place of another command or series of commands. To create an alias, type:
alias <alias_name> <command_to_be_aliased>
alias dir '
This example will execute
ls -al whenever you type
the command to be aliased contains any spaces, it must be surrounded by single quotes.
Common aliases include:
alias ll '
alias la '
Aliases that are typed at the Unix prompt will last for the current login session. If you want to have aliases automatically set up when you log in, use a text editor such as pico, emacs, or vi to put your alias commands at the bottom of your .login file. You can also put the commands at the bottom of your .cshrc or .tcshrc file.
To cancel the alias, type:
To see a list of all the aliases you have created, simply type:
To see what command a particular alias is set to, type:
This example will output
ls -al if you created the dir alias above.
Using Command Line Input in Your Alias
If you want your alias to read command line input, type:
alias <alias_name> '
alias ldir '
ls -al \!* |
This example will give a long listing of a directory you specify and then pipe it through the "more" command. So if you
ldir bin, the command
ls -al bin | more will get
If the command line input is at the end of the alias, then you do not need to include
following example will print whatever file you specify as a command line input to the printer in UCC101. So, if you type
"print essay1", the command "lpr -Pps_ucc101 essay1" will be executed.
alias print '
lpr -Pps_ucc101 \!*'
alias print '
Using a Command Name as an Alias Name
You can create an alias name that has the same name as a UNIX command.
alias edit pico
There is already a Unix command called
edit. However, when you type in a command, your list
of aliases is searched before the Unix commands are searched. Therefore, if you were to type
edit, your alias called edit would get executed, not the Unix command
If you wanted to temporarily override your alias and execute the real
edit command, you may
specify the full path to the edit command such as
February 03, 2011