College of Arts and Sciences

Department of Mathematics

Basic Unix and Linux Commands

Table of Contents
The Command Line
Using man to display the system manual
File Organization
Manipulating Files
Deleting Files
Viewing Files
File Lists
Printing Files
Command Shortcuts
Environment variables and the .cshrc file
Change your password
Add terminal shell to panel bar
Add Mathematica to your start menu


This document briefly describes commonly used C-Shell, as implemented on the Unix operating system. Included in this document are an explanation of the on-line system manual utility and descriptions of common commands. See the previous chapter for instructions onlogging on and off the computers. Contact the help desk for additional help getting started. Many of the features and commands described here are common to all UNIX shells, but since the C-shell is the one used primarily in the Math department, we will not distinguish between commands in UNIX, and commands peculiar to the C-shell.

The Command Line

The command line is the interface with C-Shell. C-Shell prompts for commands with a percent sign (%) or the hostname (e.g. eta>) when ready for command input. Commands must be entered in lower case. Extra spaces or tabs are ignored. Follow each command with the <Return> or <Enter> key.

Using man to display the system manual

The man (manual) utility displays pages from the system documentation on the terminal. This documentation is useful if you know what utility you want to use but not sure exactly how it works.

If the command is known ahead of time, type

eta> man command

for help on that command. Note that eta> denotes the prompt that whatever machine you are using supplies you - you do not need to type that.

eta> man -k word

will give you a list of utilities related to word. Another way to obtain this information is to type apropos word. You may use the command man man to find out more about the man utility.

File Organization

A file is a data collection such as a FORTRAN program, or information needed to print a graph. File names have the format: filename[.ext]where filename is a user-supplied name, ext is the extension usually consisting of characters denoting the file type. The file named odesolve.f is FORTRAN source code named odesolve that resides in the current directory.

Files are associated into groups called directories. Each user begins with a single directory, called the home directory, which contains all subsequent files and subdirectories. When you first log on to a UNIX system, the working directory is your home directory. For instance, /usr1/richards is richards' home directory. Subdirectories are created in a tree-like fashion. Set them off from the parent directory by slashes in the directory specification. Thus, /usr1/richards/papers is a subdirectory of the home directory /usr1/richards. Subdirectories help organize related files; for instance, a subdirectory fortran may contain all FORTRAN source code files. To make a subdirectory called papers off the current directory, type:

eta> mkdir papers

If there is no directory specification before the name papers, this indicates that the subdirectory should branch from the working or current directory. To set /usr1/richards/papers as the current directory, type commands:

eta> cd /usr1/richards/papers

or type

eta> cd ~/papers

where the tilde (~) by itself expands into the name of the home directory /usr1/richards.

eta> cd ~jones

changes the current directory into user jones's home directory. Typing cd without any arguments is the equivalent of clicking Dorothy's heels together: it returns you to your home directory regardless of where you are.

To find out what the working directory or current directory you are under, just type:

eta> pwd

which means print working directory.

Manipulating Files

To list the files and subdirectories contained in the current directory, type the command:

eta> ls

which stands for list. To get a list of files with their creation dates and their sizes, use:

eta> ls -l

The -l is called a flag, and stands for long. In any UNIX system there are a number of files that are usually hidden from your view. To see all files, including hidden files, type ls -a. You may combine flags, so that to see all of the details about all of your files, type ls -al.

To move a file from the current directory to richards' paper directory, type

eta> mv memo.tex /usr1/richards/paper/letter.tex

You may use mv to rename a file within a current directory, or to move it from one to another. Any valid directory specification may be used in front of the file name.

To make a copy of an existing file with the same name, type:

eta> cp odesolver.f fortran

This command could have various results, depending on your directory structure. If you do not have a directory called fortran, this command will create a copy of the file odesolver.f and call it fortran. If you already have a directory called fortran, then a new file called odesolver.f is created in the directory fortran.

The command

eta> cat plusfile >> oldfile

will concatenate the file plusfile to the end of oldfile without affecting plusfile. The command cat plusfile will concatenate plusfile to the standard output. This is an obscure way of saying that cat plusfile will list the contents of the file on the screen.

Deleting Files

Files that have outlived their usefulness should be deleted as a matter of good account housekeeping. To remove a file from a directory, type:

eta> rm directory/filename

The rm command will assume the file is on the current directory when no directory is indicated.

Since rm supports the use of filelists (see below),

eta> rm ode*.f

deletes all files of type .f whose names begin with ode. Use care with wildcards. To manage its effect, use the -i option:

eta> rm -i ode*.f, ode*.o

and UNIX will request confirmation before each file deletion.

It is also possible to delete entire directories.

eta> rmdir papers

will delete the directory papers from the current directory if the directory papers is empty. If the directory papers is not empty, but you want to delete it together with all of its contents, then use the rm -r command option:

eta> rm -r papers

Since no quotas on disk space are imposed, please use rm and rmdir often to free disk space for others who may need extra room. This give-and-take management gives great freedom in terms of disk usage and CPU time; please help support our system by employing good file management habits.

Viewing Files

To view a text file onscreen, use:

eta> cat filename

If there is too much text to fit on the screen, the excess scrolls off the top. To momentarily stop the output, type <Ctrl-S>. Continue the output by pressing <Ctrl-Q>. Most terminals also offer a <Hold Screen> key. Press the key once to halt output, press again to resume scrolling. For large files, a better solution might be to use

eta> more filename

This will type the file a single screenful at a time, awaiting a space bar between each screen. The editor can also be used to view files (see the chapter Using the UNIX Editor or on-line help).

Do not attempt to view binary files, such as files of type .o or a.out, using the above commands. These files contain symbols that can cause terminals to hang up.

File Lists

Many commands accept lists of files in their file specifications. For example, to delete two files, instead of issuing the delete command twice, once with each file, issue it once with the two files separated by spaces, as in:

eta> rm prog1.f prog2.f

The C-shell has very powerful features that may be used to create lists of files. The simplest are wildcard characters. Wildcard characters turn a single file specification into a file list by substituting for alphanumeric characters in a filename. The wildcard character * replaces any alphanumeric string, so ode*.f is equivalent to the list of all files (in the current directory) whose filenames begin with the

characters ode, and which have the extension .f. The command

eta> ls ode*.f

might provide output something like:

odesolve.f odeinit.f ode_to_urn.f ode.f

The character ? acts as a wildcard taking the place of a single character. The list designated by ?solve.f would contain rsolve.f, but not odesolve.f, or solve.f.

Another way of creating lists of files is to use logical expressions. For example, if the files paper1.tex, paper2.tex paper3.tex, and paper4.tex reside in the directory papers, and if one wants to list the contents of only the first three, then the command

eta> cat paper[1-3].tex

lists the contents of the first three files. There are many powerful features in the expansion o f logical expressions, which are beyond the scope of this document. Check the man page for csh.

Printing Files

You may print files by typing

eta> lpr filename

You must tell UNIX which printer to send the job to, either by setting an environment variable (see the section below), or by inserting the -P flag. Thus, to have the file print at the printer on the third floor, type

eta> lpr -Phpr3

There are several printers in the department to which you may send your output, as described in the table below.

Printer Name    Description          Location                 

hpr0            HP Laserjet IVsi1    Room 101W        

hpcolor0        HP Laserjet 5        Room 3        

lp4 (lp5)       HP Laserjet 4000M    Newton Lab 101W        

hpr1            HP Laserjet 4000M    1st floor printer        

hpr2            HP Laserjet 4000M    2nd floor printer        

hpr3            HP Laserjet 4000M    3rd floor printer        

To check on the status of your print job, use the lpq command. for example, to check on the status of jobs on the color printer, type

eta> lpq -Pcolor

Occasionally, after a job is sent to the printer you will realize that it was a mistake to do so. To delete the job from the queue, first find its job number by using lpq. Next, use lprm to delete it. To delete job number 23 from the color printer queue, type

eta> lprm -Pcolor 23

If you cannot find the job number using lpq, then it is too late to delete it - it is already coming out of the printer.

Command Shortcuts

C-Shell can recall a list of previous commands. Type:

eta> history

to obtain a numbered list of previous commands. To select the nth one, type:

eta> !n

To repeat the last command, type !!. To repeat the command before the last, type !-2. One may also recall commands using the first characters from those commands. To repeat the last command starting with the character v, type !v. To repeat the last command that started with more, type !more.

Every C-Shell command can be abbreviated by using the alias command. After typing

eta> alias h history

eta> alias ll ls -l

h is equivalent to history and ll is equivalent to ls -l.

Another powerful feature of the C-shell is the ability to redirect output. Ordinarily, the output from a given command goes to the screen, but there are various ways to send it elsewhere. If you want the output from a command to go into a file, you may use the > symbol. For example, the command

eta> cat myfile > yourfile

has the same function as cp myfile yourfile. By itself, the command cat myfile would cause the contents of myfile to be listed on the screen. Here the > symbol tells UNIX to write the output (the listing) on a file called yourfile. If yourfile already exists, its contents are destroyed. If it does not exist, it is created.

Frequently you will not want to destroy an existing file, but will want to append the contents of another file on the end of it. For this, the >> symbol is used. The command

eta> cat myfile >> yourfile

appends the contents of myfile to the end of the file yourfile. If yourfile does not exist, it is created. It is also possible to redirect input using the < symbol, but this will not be discussed further here.

Another useful redirection symbol is the pipe ( | ). This tells UNIX to use the output of the command to the left of the | symbol as the input for the command to the right of the | symbol. For example, suppose that the directory papers contains so many files that their names no longer fit on one screen. To view all of the names, pipe the output from the ls command through the more command, as follows.

eta> ls papers | more

Finally, in UNIX you may run jobs in the background. Normally, commands accept input from and send output to the screen. A background job is more or less detached from the screen, so that the screen is free for you to type other commands in. This is equivalent to running a job in batch mode in VMS. You could run a program such as Mosaic in the background while reading your e-mail, for example. One may halt execution of a job at any time, and change its status from foreground to background, or vice versa. The way to halt execution of a job that is running in the foreground is to hold down the <ctrl> key, and press 'Z'. Doing this stops whatever job you are doing at the time. To restart the job in the foreground, type fg and hit the <Enter> key. To restart the job in the background, type bg, and hit the <Enter> key. You may also use fg to bring a background job to the foreground at any time.

One may start a job in the background immediately. To do so, simply type the command to start the program, followed by an ampersand ( & ). For example, to run Mosaic in the background while leaving your screen available for other things, type

eta> mosaic &

To check on the status of background jobs, use the ps (process status) command. To kill a background job, use the kill command (surprisingly transparent nomenclature for UNIX, isn't it?). The following commands check on the process status of a program called myprog, and then kill it (This might occur if it's taking too long to execute - you might think that it is in an infinite loop).

eta> ps


5185 p1 I 0:00 -csh

6120 p1 I 0:59 myprog

6480 p1 R 0:00 ps

eta> kill -9 6120

The only commands entered from the keyboard were the first and last lines. The lines in between are the output from the ps command. The -9 flag on the kill command allows it to kill almost any job. You cannot kill someone elses job. Never kill the csh command, since that represents your current session.

If you try to log out, but the computer won't let you, saying that "there are stopped jobs", all you should have to do is type fg, and then kill the program that is stopped. After that, you should be able to log out. There are a number of other ways to use this feature to advantage.

Environment variables and the .cshrc file

There are a number of variables associated with your UNIX session that control such things as the location to which your screen output is sent, where your print jobs are sent, the directories that UNIX looks into for commands, and so on. You may set these variables using the setenv and set commands. Some common settings are listed below.

set path = (. /usr/local             Tells UNIX to look for commands and   
/usr/local/bin )                     other files in the current            
                                     directory, the directory /usr/local   
                                     and the directory /usr/local/bin, in  
                                     that order.  This should all be one   
                                     line (it just wrapped around here).   

setenv DISPLAY nll304:0              Tells UNIX to send screen output to   
                                     the display named nll304:0.  Your     
                                     display name should appear on a       
                                     sticker on your monitor.  If not,     
                                     contact the helpdesk.                 

setenv PRINTER hpr2                  Tells UNIX to send your print jobs    
                                     to hpr2, unless you specify           

When you log on, the C-Shell searches the home directory for a file named .cshrc. This file contains C-Shell commands to be executed at every log on, along with informational commands often entered at login time. An example of a .cshrc should demonstrate this more clearly.

source /usr1/examples/login_example

setenv PRINTER hpr0

alias h history



The first command sets the proper path variable, The second line sets the default printer to be hpr0 (in the basement room 3). The third allows you to type h to see your history list. The next prints the date on your screen. The last command shows you who is logged onto the machine currently.

If you don't want to mess with your .cshrc file, you can just type the command "/usr2/Init/fixmypath" from a Unix command line, and your .cshrc file will be set for you.

Change your password

If you are a faculty member, or a graduate student, and would like to change your password you may do it from most Unix machines. Log onto e.g. thetahat, and

  1. Type kinit
  2. Follow the instructions that are given to type your old password.
  3. Type kpasswd
  4. Follow the instructions that are given to type your old password, followed by your desired new password, twice.
  5. Log out.
Note that the change should take place immediately on research machines, but that it may take up to 24 hours to take effect on Newton lab machines. Moreover, it also changes your Windows password.

Add terminal shell to panel bar

If there isn't a terminal shell prompt located in the panel at the bottom of your Linux screen, you may add it by the following steps:

  1. Right click on the panel bar
  2. Click on "Add Applet"
  3. Move the cursor over "Utility"
  4. Click on "Gnome Pager"
OR, you may
  1. Right click on the panel bar
  2. Click on "Add new Launcher"
  3. In the Name box, type: Terminal
  4. In the Comment box: (skip this box)
  5. In the Command box, type: Gnome-Terminal
  6. In the Type box, type: Application
  7. You may choose to add an icon such as the terminal window with a penguin

NOTE: To remove an icon from the panel right click on that icon and when the menu pops up, press delete

Add Mathematica to your start menu

  1. Open a terminal and at the prompt type, gmenu which will open the Gnome menu editor
  2. Right click on "User Menus"
  3. In the Name box, type: Mathematica
  4. In the Command box, type: /usr/local/Mathematica/Executables/Linux/mathematica
  5. Press the save button
OR, you may
  1. Right click "User Menu" on the start menu
  2. Click on "Properties"
  3. Type Mathematica in the Name box
  4. Type /usr/local/mathematica/Executables/Linux/mathematica in the Command box
  5. Press the ok button

Math Home / People / Computer Services / Departmental News / Prospective Students / Current Students / Research

Webmaster Math Home Page

This page last modified on 8/10/00
Copyright © 2000 Washington State University
Please view the Disclaimer
Department of Mathematics, PO Box 643113, Neill 103, Washington State University, Pullman WA 99164-3113 Phone: 509-335-3926 Fax: 509-335-1188 Contact Us