next up previous contents
Next: Default File Handles Up: Unix C Shell Interface Previous: C Shell Initialization Files

Shell Commands

alias

The alias command allows commands or commands with parameters to be aliased with a shorter, sometimes single-character version of the command. To use alias to redefine the ls -FC command to the single character l, enter the following:

alias l ''ls -FC''

Giving the alias command without any parameters lists the aliases that are currently defined.

Place any aliases that you plan to use often in your .cshrc file so you don't have to reenter them every time you login. Another reason for placing the alias declaration in the .cshrc is that aliases are window-specific. If you declare an alias within one window, then it is only recognized within that window. Placing an alias declaration in the .cshrc assures that the alias will be available regardless of the window that you are in.

A list of aliases that you should consider placing in your .cshrc follows:

   alias cp cp -i
   alias mv mv -i
   alias rm rm -i
The -i argument specifies interactive prompting if existing data might be overwritten, a precaution that might save you a considerable amount of work in the future.

history

Commands that have already been issued are 'remembered' and can easily be repeated with a couple of keystrokes if the history command is used. In your .cshrc file, include the statement:

set history=20

The set command assigns the number of commands that history will be able to access. Include the statement 'alias h history' in your .cshrc file so that you only need to enter 'h' to get the command history list. Note that the history list is window-specific in that commands entered in one window don't show up on the history list of another.

To use the history list after following the above steps, enter 'h' after you have issued a few commands. You will see a numbered list showing the last twenty commands that you have entered. To reexecute a command, enter a bang character (an exclamation point) followed by the number of the command. Another way of reexecuting a command is to type a bang character followed by enough of a previous command to uniquely distinguish that command from others in the history list. If a previous command had been:

grep strcmp 3dlife.c

then entering !g would reexecute that command if no other command in the history list began with 'g'. If more than one command in the history list is described by the character or string after the bang character, then the most recent command in the list fitting that description is reexecuted.

If you just want to reexecute the last command typed, type two bang characters followed by a carriage return. In addition, by putting text after the bang characters you can modify the previous command. As an example, if you forgot to type the destination while copying a file you would get an error message telling you the proper syntax of the copy command:


cp /backup/*.tex <CR> 		(Missing destination for copy) 
 
To reexecute this command specifying the destination: 
 
!!latex 		(latex  is destination directory)
The text following the bang characters is concatenated with the previous command string and then the command is executed.


next up previous contents
Next: Default File Handles Up: Unix C Shell Interface Previous: C Shell Initialization Files
World Wide Web Administrator
1/5/1999