A QUICK INTRODUCTION TO UNIX
Introduction
Many computers used at Fermilab use the UNIX operating system, or close
variants thereof. This note is intended to get you oriented in your
new account, and to give you an idea of how and
where to
look for more information about the UNIX operating system. It is not
intended to replace any other documentation. More thorough
documentation is available in various reference and text books.
- Mark G. Sobell, A Practical Guide to Unix System V (Second Edition)
Benjamin/Cummings (1991)
- UNIX at Fermilab , Computing Division document GU0001. See
http://cddocs.fnal.gov/cfdocs/productsDB/docs.html (you probably had already
guessed that), and follow the link
"General UNIX documentation (GU)".
- Try seaching the WWW (e.g., www.altavista.digital.com)
for unix+summary, unix+overview, "a quick introduction to UNIX", etc.
Directory Structure
There are several ways of refering to a directory:
- Absolute: /top/sub1/sub2/...., where /top is the
top directory of the disk, and sub1, sub2, etc., are sub-directories.
- Relative:
- . (or no specification) - the current directory
- .. - parent of current directory
- ../sub1 - sub-directory "sub1" of parent
- Relative to a specific user:
- ~ - your own home directory
- ~ramberg - user "ramberg's" home directory
For example, imagine Ramberg's home directory is /usr1/home/ramberg, and
he has a sub-directory called "hyperon." If I am currently in /usr1/home/another/sub1,
I can refer to the hyperon sub-directory as:
- /usr1/home/ramberg/hyperon, or
- ~ramberg/hyperon, or
- ../../ramberg/hyperon.
Note: All file names, commands, and variables are case specific
in UNIX.
Editing Files
There are several editors available. The most intuitive is nedit. See
the section on "Products" below.
Emacs and vi are two other commonly used editors on Fermilab UNIX systems.
Basic Commands
Here are a (very) few basic commands in UNIX.
Note for reading these descriptions:
- Each of these commands has many more options than are listed here. See
an appropriate reference (e.g., the "man" pages) for the complete description of each command.
- [...] means the ... is optional.
- (a,b) means a choice between a and b.
- Words in roman font are to be taken literally; words in italics are to
be substituted with the appropriate values in each case
Commands:
- man (command, -k keyword) See man (help) pages about command or keyword.
- ls [-l] [-t] [pattern] - List files in current directory
matching pattern.
- cd [dir]- Change to directory dir
- pwd - Print working directory (show which directory you are in)
- mkdir dir - Make a sub-directory dir in the current
directory.
- mv [-i] file1 file2 - Rename file1 to file2,
overwriting file2 if it exists. The optional -i flag will require
confirmation before overwriting file2.
- chmod mode file - Change permission mode for file.
See the man pages.
- cp [-i] [-r] file1 file2 - Copy file1 to file2,
overwriting file2 if it exists. The optional -i flag will require
confirmation before overwriting file2. The optional [-r] flag will
copy recursively, i.e., including all sub-directories if file1 is
a directory.
- rm [-i] [-r] file - Remove (i.e., delete) file.
The optional -i flag will require confirmation. [-r] will delete all sub-directories
if file is a directory.
- alias - List all defined aliases (an alias is a "nickname" for a command)
- alias name - List definition of alias name
- alias name command - Define name to
mean the command command.
- cat file - Display the contents of file.
- more file - Display the contents of file, pausing
at each page.
- less file - A fancy version of more .
- head [-n] file - Display the first [-n] lines
of a file.
- tail [-n] file - Display the last [-n] lines
of a file.
- grep [options] pattern file - Look for occurances
of pattern in file. See the man pages, or a good text.
- setenv var val - Set the environment variable
var to value val.
- printenv [var] - Display the value of variable var.
Products
Commands and applications that are not part of the operating system are
defined at Fermilab as "products". In order to run these programs,
you usually need to setup the corresponding product, i.e., tell the operating
system where to find them, each time you log in:
setup product
Some useful products are:
- www - needed to run netscape.
- nedit - needed to run nedit, a very useful editor.
- emacs - needed to run emacs, another very useful editor.
- ximagetools - needed to run display.
- tex - needed to run latex and ghostview.
Important files
There are two very important files that can make using a UNIX system much easier.
- ~/.login - a set of commands that are run when you log in.
- ~/.cshrc - a set of commands that are run when you start a new
shell.
[Note: File whose names begin with ".", such as ".login", are "hidden" files.
They do not normally appear in a simple ls command, unless you give the
-a option.]
A starting version of each of these are provided with your new account. As
an exercise, you can do the following:
- cd - go to your home directory.
- cp .login .login.bak - make a back up copy in case someting goes
wrong (some editors do this automatically.)
- cp .cshrc .cshrc.bak
- setup emacs (or nedit)
- emacs (or nedit, or vi if you're tough) .login
Now you're editing the .login file. This is the best place to set
variables that you'll need, as well as setup any products that you use
very frequently.
When you're done, try editing .cshrc. You'll notice that some aliases have
been suggested, but they are "commented out," with the c-shell comment
character "#". The aliases re-defining the commands cp, mv, and rm
to always use the -i (confirm) option are a very good idea.
To activate them, remove the initial "#", save the file, logout, and
then login.
The standard UNIX command lpr is replaced at Fermilab with flpr.
This allows most printers to be accessed from most machines. The key commands
are (see the man pages for more info):
- flpr -q queue file - Send the file file to the
queue queue. If you have the environment variable FLPQUE defined,
then omitting -q queue is equivalent to -q $FLPQUE.
- flpq -q queue- Find the status of the queue queue,
including the print jobs already in the queue.
- flpk ...- Remove a job from a print queue. See the flpr man
pages for details on how to use it.
The names of the printer queues are posted near each printer.
Postscript Files
Postscript is a graphics language used widely at Fermilab and elsewhere.
Typeset papers, plots made by programs such as PAW,
and other figures
are often written in postscript. Many printers at Fermilab interpret
postscript automatically. In this case, you can send a postscript file
to the printer as you would any other. In some cases, however,
it is necessary to
specify a special queue on a printer when printing postscript.
The names of such queues often are the default with "_ps" added. If
you fail to specify a "postscript queue" when necessary, the raw
postscript language will be printed, instead of the graphics you intended.
Note: To view a postscript file on the screen, use ghostview.
Variables
The UNIX system supports variables. You can read about them in any thorough
reference. The value of a variable var is refered to as $var.
Connecting to Other Computers
Two particularly useful means of connecting to other computers are
given below. See a good reference for others.
- telnet name - Connect to the computer defined by
name (e.g. fsgi02.fnal.gov), and open a session on it.
- ftp name - ("File Transfer Protocol") Open a connection
for transfering files to or from name.
Hints
Some topics to look for in references which may lead you to more useful
information:
- background
- Bourne Shell
- C-Shell
- command line editing
- hidden files
- history
- path
- redirection (pipes, etc.)
- regular expressions
- rehash
- setenv
- shell scripts
- source
- which
P. Shanahan - 6/3/98
http://ppd.fnal.gov/experiments/ktev/unix_guide.html