Making an alias for a command
Aliases allow you to assign long or complex commands to short comands
or "nicknames" which are easier to remember as well as to type.
For example, instead of typing:
ls -alFs | more
you can make your account perform the same action (listing files) by aliasing
the command to just:
l.
You can make temporary aliases or, for often-used commands, permanent
ones.
The alias command can be used three ways.
- Examine existing aliases.
- Create temporary aliases.
- Create permanent aliases.
Use the unalias command to remove temporary aliases or
disable permanent aliases (please see bottom of this page).
Examining existing aliases
Entering the alias command all by itself (with no arguments)
lists all active aliases (there are several aliases which are pre-set for
all Unity accounts).
Entering the command alias name displays the
named alias' definition. For example, entering
alias goto
results in
[sparc03]...kaputnik>alias goto
set d1 = $cwd; cd !^
[sparc03]...kaputnik>
The goto command is clearly easier to type and remember
than what it stands for!
Creating temporary aliases
You can create temporary aliases of your own by following the syntax
alias name definition
where name is the abbreviation you want to use in place of the
big, nasty Unix command, and definition is the actual Unix command
you want to replace.
Entering the alias at the command line creates a temporary alias.
For example, you can set cls to substitute for the clear command,
which clears the screen, by entering
alias cls clear
Or you could establish an alias for the ls command (which
lists files) that includes the -s option (which provides the size
of the files) by entering
alias l ls -s
Aliases created in this way, however, will be active only for the current
session. When you logout, your alias is lost.
Permanent aliases
To create permanent aliases you must modify your ".mycshrc" file. Open
the file with an editor (such as TED or Nedit) and type the alias command
you wish to activate. Be sure to put the command on a single line. The
alias will be active until it is removed from the file or until you use
the unalias command on it (see below).
For example, if you wanted to alias the command "zwho | grep
1004tuc ; zwho | grep -c 1004tuc" which makes a zwho list
of the people in Tucker Lab:
- Open the text editor by doing one of the following:
- Type ted or Nedit at the prompt.
- From the Application menu (mouse button 2), choose one of these
from the Editors sub-menu.
- Open the file ".mycshrc". if you don't have one, create a new file
with this name. (The file must be located in the root directory!)
- Add the line:
alias tucker "zwho | grep 1004tuc ; zwho | grep -c 1004tuc"
- Logout and log back in. Note: Changes to a file usually
WILL NOT take effect until you do this.
The command tucker will now work the same as "zwho
| grep 1004tuc ; zwho | grep -c 1004tuc" and tucker is
also easier to remember and takes less time to type!
For more information about customizing your environment see Customizing your Unity account.
Removing aliases
To remove a temporary aliase use the command unalias name.
For example, if you had set scan as an alias for the command
sequence more -cs, you would remove the alias by entering unalias
scan.
Using the unalias command on a permanent alias (one
which is defined in your ".mycshrc" file) removes the alias for
that session only. When you logout and then login again
the alias will still be in effect.
To remove a permanent alias permanently you must remove the line in your ".mycshrc" file
that defines it.
Last modified
July 20, 2004
by cawalker
|