The UNIX shell is a program that accepts commands from a user and executes them. The shell effectively surrounds the UNIX kernel, which is a special program having exclusive access to the computer hardware (memory, processor, disks, etc.) which other programs need to run.
Several UNIX shells are available here at USC including:
All new ITS UNIX accounts are set up with tcsh as the default shell. To see what shell you currently have running, type:
To see your default shell, type:
and look at your shell variable. You can change your default shell at any time by typing
chsh at the UNIX prompt.
Each shell sources a different configuration file when it is invoked. These are the corresponding configuration files:
||.tcshrc or .cshrc|
||.bash_profile, .bash_login or .profile|
You can invoke a shell at anytime by typing the shell name at the UNIX prompt. For example, you could type
tcsh to start a T shell. You must type
exit to close the
current shell and return to the previous shell.
For more information on any of the above shells, type:
ITS Consulting Supports supports only csh and tcsh. The following are some useful features of csh and/or tcsh.
History Mechanism (csh & tcsh)
By default, both shells keep track of the last 25 commands you have typed in. To see the last 25 commands you have
typed in, type
You can execute previous commands without retyping them by typing:
which will execute the command numbered 14.
You may also use:
which will execute the last command starting with
If you want your shell to remember more than your last 25 commands, add the following command to your
If you want your shell to remember your commands after you logout, you can modify your
.cshrc file so that the next time you login, those commands will appear in your history list.
Add the following command to your
Note: make sure the value of your
savehist variable is less than the
value of your
savehist is set, your history list is saved into a file called
.history when you logout. The next time you login, your
file is read back into your history list.
Command Line Editing (tcsh)
If you use tcsh, you can edit the command line using the arrow keys and emacs key strokes. Type
man tcsh for more information. Some common emacs keystrokes are:
^P previous command
^N next command
^F move the cursor forward
^B move the cursor backward
^U delete the entire line
^Y undelete the entire line
^D delete the current character
^A go to the beginning of the line
^E go to the end of the line
Filename Completion (csh & tcsh)
For csh, if you type in a partial filename and type the
Esc key, one of two things will
happen. If the partial filename is unambiguous, the shell will fill in the remaining characters of the matching filename
from the current directory.
If the partial filename is ambiguous, the shell will beep at you to indicate that either no file starts with the partial
filename, or more than one file starts with the partial filename. To list all the possible filename completions, type in a
partial filename and then type
For tcsh, if you type in a partial file, directory, command or variable name and hit the
Tab key, one of two things will happen. If the partial name is unambiguous, the shell will fill in the
remaining characters of the matching file, directory, command or variable. If the partial name is ambiguous, the shell
will beep to indicate that either no file, directory, command or variable starts with the partial name or more than one
file, directory, command or variable starts with the partial name. To list all the possible file, directory, command or
variable completions, type in a partial name and
With tcsh, you can also use wildcards in a file, directory or command name and then request a list of all possible
completions by typing
<Control>-x g. For example:
With tcsh, you can also complete the expansion by typing
For example, if you type:
Your command line will be expanded to all the filenames that end in .c for example:
ls prog1.c prog2.c prog3.c
You can then edit the command or type
<Return> to execute the command.
Spelling Correction (tcsh)
With tcsh, you can correct the spelling of a filename. If you type in an incorrect filename on the command line and
<Esc> s before you type
<return>, tcsh will
correct the misspelled filename. For example, if you had a file named
assignment, but you
Instead of backing up and retyping the word, you can type
<Esc> s and the shell will
attempt to correct the filename by matching it against all the files in the current directory.
You can also have tcsh correct mispelled command or variable names by putting the following command in your
Then, if you mispelled enscript, instead of backing up and retyping the command, you could type:
Changing the Default Prompt (csh & tcsh)
You can change the default prompt for csh and tcsh by putting the following command in your
set prompt = "<whatever you want your prompt to be>"
set prompt = "Yes, master?"
For tcsh, you can also use variables in your prompt. Some example variables are:
%c current working directory
So if you type something like:
set prompt = "%m %c %t (%h): "
Your prompt will look something like:
aludra ~ 10:53am (1):
You can also use underline, bold or reverse text portions of your prompt by surrounding them with variables such as:
%u <text> will be underlined
%b <text> will be bolded
%s <text> will be in reverse text
So if you type a command like:
set prompt = "%S%m%s%B%c%b%U%t%u(%h):"
You prompt will look like:
aludra current_dir 10:58a (2):
where aludra is in reverse, the current working directory is in bold, and the time is underlined.