To create a simple command alias:
alias del 'rm -i' del memo.txt rm: remove memo.txt? y
This creates the alias del for the command rm -i which prompts you for confirmation that you want to remove a file before it does so.
You can make this alias a permanent feature of your environment by adding it to your shell start up file .cshrc.
To create a command alias that consists of several commands:
alias what 'ps -aux | grep $USER | less'
This creates the alias what.
Entering the command what will now run the command
ps -aux | grep $USER | less
which consists of three commands linked together with pipes.
To refer to another command alias within an alias:
alias h history alias rev 'h | tail -10'
The first command assigns the alias h to the history command. The next command assigns the alias rev to the command h | tail -10. This takes the output from the alias h ( the history command) and pipes it through the tail command to list the ten most recent commands in the command history.
To pass command arguments to the alias:
alias print 'lp \\!^ -dps5'
To print a file to the printer ps5 the user enters a command such as:
print memo.txt
The notation !^ causes the first argument to the command alias print to be inserted in the command at this point. The command that is carried out is:
lp memo.txt -dps5
Notice that the ! character is preceeded by a \\ to prevent it being interpreted by the shell as a history command.