Your Shell

colored bar

Your interface with unix

Once you have logged into a Unix computer, the first thing it does for you is run your shell. Your shell is a program that lets you interact with the system using a command line interface. When logging in to the console of some Unix computers, the computer will first start X windows, but eventually you will run a terminal program that will give you your shell. Your shell is simply a program which lets you run other programs on the system, such as cp or rm for file manipulation or emacs to edit files. It may have many features for making this easier using a command line interface. Both tcsh and bash have command line recall which lets you scroll through the history of commands you gave the shell using the up and down arrow keys. Both have command editting which allows you to edit in line your command using the left and right arrow keys. Both have file name completion which lets you type on the first part of a file's or directory's name and then press the tab key to complete it.

One thing very important to keep in mind when typing commands to the shell is that must punctuation symbols mean something special to it. Therefore if the name of a command or file contains a non-alphanumeric character, you should enclose the name in single quotes. For example

rm 'mail from bill@facstaff'
Note that the space character is considered a special character.

Shell Globbing

One of the main uses special characters is shell globbing. Globbing allows you abbreviate file names or to specify many file names using simple expressions. For example, to remove all files in the current directory that end with the letters ".txt", you would type
   rm *.txt
The special characer "*" is called a wild card meaning it matches any number (including zero) of any character. If the files atom.txt, electron.txt, and quark.txt existed in your directory, the above command would be "expanded" to
   rm atom.txt electron.txt quark.txt
Similar to "*" is "?" which stands for any one character. For example,
   rm c?t
would remove the files cat, cot, and cut but not coat or ct. A c*t would have removed all these files. Using square brackets which contain select characters operate like a selective "?". For example,
   rm c[au]t
would remove the files cat and cut, but not cot or any other file.

Often your will want to list several files on the command line that are not in the current directory. It is painful to have to type the same pathname to all these files. This is were the curly brackets are useful. For example,

   rm /usr/tmp/{game.log,temp.txt,doom.tmp}
removes the files game.log, temp.txt, and doom.tmp in the /usr/tmp directory.

A tilde with no alphanumeric character immediately after expands to your home directory. A title followed by a user's login name expands to that users home directory. For example,

   cp ~raines/.emacs_full ~/.emacs
copies the file .emacs_full from raines's home directory to the file .emacs in your home directory.

All these things can be combined too!

   rm ~/games/{c[ao]t,*.txt}

Input/Output Redirection and Piping

Programs that take there input from the keyboard on a line-by-line basis (i.e. they are not an X-windows program or a menu-driven program like pine or elm), can be told to get their input from a file instead. To do this, use the the '<' symbol at the end of the command. For example,
   mail -s "The Data" armd@physics < nmr.dat 
would mail the contents of nmr.dat to user armd. For programs that output on a simple line by line basis to the terminal, the '>' symbol can be used to redirect that output to a file. For example,
   sort < phone.list > newphone.list
uses the sort program to sort the lines in the file phone.list and place them in the new file newphone.list. If you only want to append to an existing file, use the '>>' symbox instead.

The '|' symbol, called the pipe symbox, can be used to connect the output of one command to the input of another. For example,

   grep George phone.list | sort
uses the grep program to find all lines in phone.list containing the word George and then passes it to the sort program which print the lines sorted on your terminal. You can connect as may programs as you need this way.

Shell configuration

You can dramatically change the way you interact with the operating system by changing the files that control the configuration of the shell and X windows. Depending on whether you use the csh or tcsh shells or the bash shell, you can control how commands work by setting aliases in your .cshrc or .profile files, respectively. These files are loaded when you login. Here are some alias examples for each.

.cshrc

alias mail 'pine'
alias Mail 'pine'
alias man 'man -F'
alias cp 'cp -i'
alias rm 'rm -i'
set prompt=("Your command? ")
.profile
alias mail= "pine"
alias Mail="pine"
alias man= "man -F"
alias cp= "cp -i"
alias rm= "rm -i"
PS1="Your command? "
These aliases help you by relieving you of having to think as hard while you are computing. The -i flag on the copy and delete commands make them ask if you really want to overwrite or remove the target file. I've already aliased these for you in an attempt to head-off disaster.

colored bar

Last modified 9/12/96
College of William and Mary, Dept. of Physics

raines@physics.wm.edu