UNIX Survival (UNIX 101)
This page was taken from Genome Center Computing Help home page
and slighly modified.
This document provides a basic introduction to UNIX and descriptions of some essential
The UNIX file system is composed of two types of entities: files and directories.
Every file and every directory has a pathname which indicates where that file or
- Files store information. There are many types of files. Two of the more common types are
text files, which you read, and executable files, which you run. If you choose the option
"Save As..." at the bottom of this window, a dialog box will appear and prompt
you for a "Name for saved document:". If you type in a name and choose
"OK," a text file will be created under the name you provided. Files with names
starting with a period (i.e. .xstartup) are invisible in normal UNIX use. You can
see them by using a variation of the lscommand. Just don't delete them. They are
there (and invisible) for a reason. Filenames in UNIX generally do not contain embedded
spaces. If you end up with a filename with embedded spaces, you can refer to it by
enclosing the name in double quotes.
- Directories organize files and other directories, creating the tree structure of UNIX.
When you login to your account, you arrive in your personal home directory, the root of
your personal section of the UNIX file system tree. Your home directory, in turn, is a
subdirectory within other directories in the file system.
- Files and directories are specified by pathnames. The pathname of a file indicates its
location in the filesystem. Two files can have the same name as long as their pathnames
are different. If you choose the option "Save As..." at the bottom of this
window, the dialog box asking you for a filename will automatically fill in the pathname
of your home directory. An example of a pathname for a user's home directory is
/usr/jpower. The pathname for that user's mail directory might then be /usr/jpower/Mail.
When you tell UNIX to look for a text file, it checks for that file in the current
directory. If the file is in another directory, you must supply the pathname to the file.
- The command cd my_dir changes your position to the directory specified, in
this case my_dir. The command cd without an argument moves you to your home
- The command cp first_file copy_file copies the contents of first_file
into the file copy_file. To indicate that the new file is to have the same name as first_file,
use a period (.) instead of of providing a name for the second file. (In this case, the
files must be in separate directories, as two files cannot have the same name if they are
in the same directory.) For example: cp some_directory/my_file . copies my_file,
located in some_directory, and creates a file named my_file in the current
- The command lpr print_file sends print_file to the default printer
(see echo). The form lpr -Pother_printer print_file sends print_file
- The command ls lists the files in the current directory. The form ls -F
shows the difference between directories and ordinary files. The form ls -a lists
all files, even those that are normally invisible in UNIX (files whose names start with a
period, i.e. .xstartup).
- The command mkdir new_dir creates a new subdirectory named new_dir
in the current directory.
- The command more my_file displays the text of my_file one page at a
time. To see the next page, hit the space bar; to see the previous page, type b; to
quit paging the file, type q.
- The command mv file_name dir_name moves the file file_name from the
current directory into the directory dir_name, where dir_name is a
subdirectory of the current directory. The form mv old_file new_file renames
old_file and calls it new_file.
- The command pwd prints the pathname of the current, or working, directory.
- The command rm my_file deletes my_file. The form rm -i my_file
asks if you really want to remove the file my_file before it proceeds.
- The command rmdir my_dir removes the directory my_dir. The
directory must be empty before it can be deleted.
note: If you get an error
message that a directory is not empty when it appears to be, check for invisible files
- The command echo MY_VARIABLE displays the current value of environment
variables. Two variables that might interest you at some point are $PRINTER and $DISPLAY.
- The command finger user_name gives you information on the user specified
by user_name. The argument user_name can be the name of someone locally
(i.e. jpower) or someone at a remote location (i.e. firstname.lastname@example.org).
- The command grep string filename searches filename for string.
It outputs every line which contains string. The form grep -v string filename
outputs every line which does not contain string. The argument string is
read by grep as a regular expression.
- The command kill my_process sends a terminate signal to the process
specified by the process id (PID) my_process. In cases where the terminate signal
does not work, the command kill -9 my_process sends a kill signal to the
process. For info on getting the PID for a process, see ps.
- The command lpq outputs the current queue for the default printer (see echo).
The form lpq -Pother_printer outputs the current queue for other_printer.
- The command lprm job_number removes job_number from the queue for
the default printer (see echo). To remove a job, you must be the owner of that job.
To find job_number to send to lprm, use the command lpq. The form lprm
-Pother_printer job_number removes job_number from the print queue of other_printer.
- The command man command displays the UNIX manual page for command.
The manual pages describe usage and options for every UNIX command.
- The command passwd allows you to change the password you use to login to the
computer. The process is self-explanatory once you type the command.
- The command ps lists the processes running on your machine. The form ps gux
lists only your processes. The form ps aux lists all processes running on your
machine. The second column of the listing, the PID column, provides the information
required by the kill command.
- The command whois lookup_string performs a directory lookup on persons at
your home institution, where lookup_string is all or part of someone's first name,
last name, or phone number.
- By convention, a UNIX command reads input from standard input (the keyboard). To
get a command to read from a file instead, you need the command, the filename, and the
character '<' : my_command < my_input. Think of the '<'
as an arrow pointing in the direction the data is flowing, from the file to the command.
- The output of a UNIX command is sent to standard output (the screen) by
convention. To get a command to send the output into a file instead, you need the command,
the filename, and the character '>' : my_command > my_output.
The arrow analogy holds true in this direction as well, with the data flowing from the
command to the file. To append the output of a command to a file without erasing its
previous contents, use the notation : my_command >> my_output.
- If you have a series of commands in which the output of one command is the input of the
next, you can pipe the output through without saving it in temporary files: first_command
| next_command. For example, if you wanted to print out a sorted version of a file
that contained a list of names and phone numbers, you could use a pipe (as well as input
redirection): sort < my_phone_list | lpr.
The carat symbol (^) represents the control key.
|^C: Abort the current program or process. |
|^D: Exit xterm, ftp session, telnet session, gcg session, etc. |
|^Z: Suspend execution of the current program or process. To restart execution in
the foreground, type fg. To restart execution in the background, type bg. |
The carat symbol (^) represents the control key. More help is available in pico
with the command ^G.
- file management
|^R - read/insert file |
|^O - write out to file (save as) |
|^X - close file and editor |
|^C - cancel |
|^D - delete character |
|^K - delete line |
|^U - undelete line |
|^F - go forward one character |
|^B - go back one character |
|^E - go to end of line |
|^A - go to start of line |
|^V - go to next page |
|^Y - go to previous page |