AliasesAn alias allows you to create your own names for commands. Aliases are used for two purposes: (1) you can rename exisitng commands, or (2) you can group commands together to create entirely new commands. This is a very powerful feature of the Unix Korn and C shells.
alias rm "rm -i" alias dir "ls -al | more" The syntax for the alias command is:
alias name value The first argument to the alias command is the name of the alias you are creating, such as dir. The second argument to the alias command is the actual command(s) that will be executed when you type in the name of the new alias. Using the examples above, when you type dir, the actual command that is executed by your C shell is "ls -al | more". In your home directory it would look something like this:
sys_name% dir total 12 drwxr-xr-x 2 stu1 class 1024 Mar 25 10:56 . drwxrwxr-x 7 root sys 96 Mar 25 10:22 .. -rw-r--r-- 1 stu1 class 0 Mar 22 14:28 .news\_time -rw-r--r-- 1 stu1 class 1956 Mar 25 10:52 .profile -rw------- 1 stu1 class 222 Mar 25 10:56 .sh\_history -rw-r--r-- 1 stu1 class 64 Feb 3 13:39 .vtlrc -rw-r--r-- 1 stu1 class 531 Feb 3 13:39 .vtlrc.els sys_name% _ As mentioned, you can assign new names to existing Unix commands with the alias command. Why would you want to rename an existing Unix command? How about the following example?
alias rm "rm -i" In this example, you have "safeguarded" the remove (rm) command. In this way, each time you attempt to remove a file by typing "rm filename", you will be prompted with "are you sure" before the file is removed. This gives an extra layer of protection from accidently deleting valuable files. Why else would you want to rename a Unix command? How about "grep"? If you type the command alias by itself, the C shell will list all of the currently defined aliases:
sys_name% alias dir "ls -al | more" disk "df -k" h history k9 "kill -9" md mkdir rd rmdir vt100 "set term=vt100" what "ps -ef" wy60 "set term=wyse60" sys_name% _
Subsections
Next: Other alias notes: Up: The C Shell Previous: Hashing and Hash Tables   Contents |