Skip navigation

STANFORD UNIVERSITY

INFORMATION TECHNOLOGY SERVICES

Getting started in Unix

Overview

This is an older document that is presented here for information purposes. It is not regularly updated and some information may be dated or incorrect. Caveat emptor.

Getting Started in UNIX


                        Getting Started in UNIX

                             September 1994

                          Stanford University
======================================================================
Contents:

Part I: Before You Begin

Part II: Beginning Unix

     Essential Information

     Logging In and Out

     Getting Information

Part III: Working with Files and Directories

     Managing Directories

     Managing Files

     Advanced Procedures

     Non-AFS Security

     AFS Security

Part IV: The Shell Program

     Customizing Your Session: Defining Your Shell Environment

     Re-Directing I/O and Building Pipes between Commands

     Controlling Jobs

     Keeping Command History

Part V: Using EMACS

Part VI: Printing

Part VII: Staying Informed about System Activity

Appendix A: UNIX Command Summary

Appendix B: Using Compilers-A Quick Guide

Copyright 1994 by the Board of Trustees of Leland Stanford Junior

University

Part I: Before You Begin

========================

What is UNIX?  Every computer-mainframe, workstation, or microcomputer-

has an operating system that allows the users and the computer to

interact.  As an operating system, UNIX is responsible for managing

computer resources and allocating and scheduling these resources to

serve the needs of individual users.  Developed at Bell Laboratories in

the early 1970's, UNIX (a registered trademark of AT&T Bell

Laboratories) originally ran on a DEC PDP-11 computer.  After the

introduction of the DEC VAX computer, UNIX was modified to run on it.

As University of California at Berkeley made many enhancements, their

version of UNIX began to diverge from the Bell Labs version.  Today

there are many different versions of UNIX.


Why UNIX?  With its programming tools, application programs, and

networking facilities, UNIX provides a powerful, versatile computing

environment.  Use of UNIX is widespread, and with the advent of UNIX

workstations, it continues to grow in popularity.  Why then is UNIX

desirable?

*  UNIX is a general purpose, multi-tasking (capable of handling

   multiple requests simultaneously), multi-user, interactive operating

   system.

*  Since most of UNIX is written in a high level language, it can run on

   many different computer systems.

*  There is a wide variety of applications compatible with UNIX.


About This Document:  Getting Started in UNIX explains fundamental UNIX

concepts, providing the novice user with the information necessary to

use basic UNIX commands, to run a few useful programs, and to manipulate

files effectively.  The Leland Systems at Stanford University are

distributed UNIX systems that include workstations from DEC, IBM and

Sun, found on the second floor of Sweet Hall; Cardinal, a DEC 5000/240

compute server; Leland, a DEC 5000/240 mail server; and Power and

Wisdom, the UNIX systems for the Social Sciences.  Information in this

document applies to all these systems.

Part II of Getting Started in UNIX takes you through an initial UNIX

session, teaching you how to log in, give the computer some simple

commands, and log out.  Subsequent sections describe the following

commonly-used procedures:

*  working with files and directories,

*  using the shell (the program that reads your commands and invokes

   programs to carry them out),

*  editing text files, and

*  printing.

Sample Sessions:  Throughout this document, sample sessions show what

you would see on your monitor during relevant work sessions.  Sample

sessions include prompts and commands.  The UNIX system uses a prompt to

tell you it's ready to accept your next command.  This prompt is usually

the name of the computer followed by >, e.g., elaine24>.  In sample

sessions, the commands you type appear in bold type, and what UNIX

displays on the screen is in normal type.  Thus, in the sample session

on page 2, you would type date only.  Text on the right side of the page

is additional commentary or more detailed instruction to help clarify

the example.  In this sample session, the text explains that you must

press the RETURN key after typing date.  Special function keys on your

keyboard, like RETURN, are shown in all capital letters and in bold

type.

elaine24> date                      After you type date, press the

Thu July 7 8:38:25 PDT 1990         RETURN key.

If what appears on the screen during a sample session is lengthy, it may

be abbreviated within angle brackets to conserve space, e.g., .  The first sample session in the Logging In section of Part

II contains this example.


Other Documents:  Throughout Getting Started in UNIX, references are

made to some of the other documents available on the second floor of

Sweet Hall;.  Most of these documents are available in their original

formats through any Macintosh connected to SUNet.  From the Chooser,

open the Computing Distribution file server in the Stanford zone,

register as a guest, and open the Computing Documents folder and then

the Sweet Hall Documents folder.  Most UNIX documents are also available

in text-only format directly through the distributed UNIX systems.  Type

help docs at the system prompt for a menu of which documents are

currently available.


Getting Help:  If you have questions about using the Leland Systems;,

contact the consultants; on the second floor of Sweet Hall at 725-2101.

You can also send computing questions to the consultants via computer,

using the electronic mail address consult@leland.


Part II: Beginning UNIX

=======================
About Part II:  Part II shows you how to access a UNIX host, begin and

end a work session, set your terminal type, change your password, and

get help when you need it.

Usually people share a UNIX computer system, called a host. Each person

must have an account; accounts provide a necessary means of regulating

each person's use of the system.  A username and password identify an

account.  Your username is the way you identify yourself to the system;

your password verifies your identity.  The document Introduction to the

Leland Systems tells  you how to open a UNIX account on the Leland

Systems.

Essential Information

---------------------
Commands:  Commands are directions you give to the computer.  They are

usually English words or abbreviations.  To give the computer a

commands, type the command name and press RETURN.  For example, if you

type the command date at the prompt and press RETURN, the computer

displays today's date on your screen.

Arguments and Options:  Many UNIX commands allow you to attach one or

more arguments.  Arguments determine the way in which the command

carries out its function.  Names of computer files, time limits, and

other information that constrains or defines the scope of a command are

arguments.  For example, the command cd tells the computer to change

from the current directory to another one.  To move to a subdirectory

named Mbox, you would use its name as an argument to the change

directory command, i.e., cd Mbox.  Mbox would then become your working

directory.

An option is a special kind of argument preceded by a hyphen (-).  It

tells the computer to execute a particular variation of the command.

For example, ls tells the computer to list the files and subdirectories

contained in your working directory; ls -l tells the computer to list

them with additional information about each file.

Command Sequences:  There are many command sequences that are helpful

when you use UNIX.  Control sequences, for example, are used extensively

in EMACS, a popular text editor, as well as in the normal UNIX shell.

To type a control sequences, hold down the CONTROL key and type the

designated letter.  Control sequences are represented in this document

as C-x.  To enter the command C-c, you would hold down the CONTROL key

while you type c.

The ESCAPE key is used in a similar manner, but instead of holding down

the ESCAPE key while hitting another key, you hit them one after the

other.  Escape sequences are represented as ESC x.  To enter the command

ESC f, you would press the ESCAPE key and then type f.escape sequences

The following keys and command sequences may prove especially useful to

you when you are first using UNIX:

DELETE or                           erases the last character you typed.

BACKSPACE

C-c                                 stops or interrupts a program

                                    currently running.

C-s                                 freezes the program's output on the

                                    screen (but the program may continue

                                    to run).

C-q                                 unfreezes the output suspended by

                                    C-s.

IMPORTANT NOTE

--------------
UNIX is case sensitive.  That is, UNIX differentiates between upper case

and lower case letters.  Therefore, typing Open is not the same as

typing open or OPEN.  Pay special attention to case when you use UNIX.





Logging In and Out

------------------



Logging In:  Your Leland Systems account allows you to log in to one of

the distributed UNIX systems.  These include Cardinal, the DEC 5000/240

that has replaced Leland for direct logins, and all of the UNIX

workstations listed below.  (Power and Wisdom are available only to

authorized users in the Social Sciences departments.) logging in



Workstation type                    Login to

----------------                    --------

DECstations                         adelbert1-adelbert26

IBM RS/6000s                        rs1-rs13

Sun SPARCstations                   elaine1-elaine54



To begin a work session, type your username and password.  Notice that

your password does not display on the screen as you type it.  This is

added protection provided by the UNIX system so that curious eyes cannot

read your password.  If you make a mistake, you must type both your

username and password again.  You are given several chances to type them

in correctly, after which you will be disconnected.  Once you

successfully log in, the system displays its prompt and waits for your

commands.





login: tsoi                         Type your username.

Password:                           Type your password.

DSO AFS (R) 3.2 Login

Last login: Thu July 7 16:52:01 from 36.83.0.150

Sun SPARCstation 2, SunOS 4.1.2, 32MB RAM, 190MB swap

-------------------------------------------------------------------

Mail questions to consult@leland; mail problems to action@leland.

-------------------------------------------------------------------

                   System messages may appear here.

                                    These messages tell you about any

                                    changes in the system you are using.

elaine24.Stanford.EDU>





Setting the Terminal Type:  When you set your terminal type, you tell

the UNIX system what type of display you are using.  Each time you

connect to a UNIX system, you should set the terminal type.  Use the

command set with the argument term=terminal type.  Following is a list

of the terminal type command settings for microcomputers and

workstations:



DECstation                          set term=xterm

IBM RS/6000                         set term=xterm

Microcomputer                       set term=vt100

SPARCstation with the X Window      set term=xterm

System, Version 11

SPARCstation without the            set term=sun

X Window System



To make setting the terminal occur automatically at the beginning of

every work session, follow the procedure in Customizing Your Session on

page 15.





Window Systems:  If you are using a workstation console in Sweet Hall,

you may use a window system, such as X.  (You automatically enter the X

Window System when you log in to a DECstation.)  A window system is a

collection of software that makes it easy for you to take full advantage

of the graphics and display capabilities of a workstation.  Different

window systems are available on each type of workstation; to see which

systems you can use on your workstation and how to activate them,

consult the Tips sheet posted in the cubicle where you are working.  For

details on the X Window System, the most widely used of the available

windowing systems, see Using the X Window System;.





A Note About AFS:  Many Leland Systems accounts (including all Power and

Wisdom accounts) are AFS-based UNIX accounts AFS-based accounts (as

opposed to NFS-based accounts).  (If the pwd command says your home

directory is in /afs/ir, you have an AFS account.)  AFS is a method by

which different computers may share the same files, conserving disk

space and making a wider variety of computers available to each user.

Because of the increased file security offered by AFS, extremely long

login sessions and extremely long-running programs (longer than 25

hours) may be problematic.  For information on how to successfully run

programs requiring more than 25 hours of real time, contact a consultant

at 725-2101 or send mail to consult@leland.





Changing Your Password:  You may want to change your password

occasionally to preserve the security of your account.  (You cannot

change your username after you have opened your account.)  Your password

must not be any word found in the English dictionary, your username, or

any permutation of your name or initials.  It is recommended that your

password be a combination of letters and numbers.  You can change your

password with the password command at the system prompt.  Remember, when

you type your password, it won't appear on the screen.



elaine24> password

Changing password for tsoi

Old password:                       Type your old password.

New password:                       Type your new password.

Retype new password:                Type your new password again.



Logging Out:  Logging out ends your work session.  If you do not log out

when finished, someone else can continue working on the computer with

your account.  If a message on the screen indicates there are stopped

jobs, be sure to 'kill' them before logging out.  See Controlling Jobs

on page 19.logging out



elaine24> logout                    Type logout.







Getting Information

-------------------



The UNIX Online Manual:  The reference manual for the Leland Systems is

online;, so you can get descriptions of UNIX commands as needed.  The

man and apropos commands give you access to the online reference manual.

The manual is organized by command; as a novice, you may find that the

difficulty is knowing which command you need to read about.  As shown in

the following sample session, you can use the -k option with man to

obtain a list of topics related to a particular key word.  UNIX online

manual



elaine24> man man                   This displays the section of the

                                    manual describing the manual display

                                    program itself.  Press the space bar

                                    to display the next screenful of

                                    information.  Type q to leave the

                                    manual and return to the system

                                    prompt.



MAN(1)                   USER COMMANDS                     MAN(1)



NAME

     man - display reference manual pages; find  reference  pages

     by keyword



SYNOPSIS

     man [-] [-t] [-M path] [-T macro-package]  [[section]  title







elaine24> man -k password           This shows all commands associated

                                    with the keyword password.  Same as

                                    the command apropos password.



crypt, _crypt, setkey, encrypt (3)  - password and data encryption

getpass (3V)                        - read a password







elaine24> man password              This displays the section of the

                                    manual describing the command

                                    password.



PASSWorD (1)     USER COMMANDS      PASSWD (1)

NAME

     password - change local or NIS  password  information



SYNOPSIS

     password [ -l | -y ] [ -afs ] [ -d [ username ] ] [  -e  username ]

     [ -F filename ] [ -n numdays username ]

     [ -x numdays username ] [ username ]







Most commands in UNIX run programs; you can find documentation for

almost all of these commands with man command.  However, some commands

are built into the shell program; you can find documentation for these

commands with man tcsh.  For more information about the shell program,

see Part IV.





Online Tutorials:  You can also learn more about UNIX by typing learn at

the system prompt.  It will show you a menu of tutorials that are

available and give instructions on how to use them.  Note that the learn

tutorial does not  cover information specific to AFS-based accounts.  If

you are using an AFS-based account, the information under the files

topic will be largely accurate but incomplete.  For more information on

AFS-based topics issue the command cd ~consult to access the file in the

consult directory.  Change to the pub directory and then to afs, and

consult the file afsguide.



Other Sources:  Printed copies of UNIX and workstation manuals are

located on the second floor of Sweet Hall for your reference.  Printed

and online versions of UNIX documents are also available.  See Other

Documents on page 2 for details.  And, as stated earlier, the

consultants can answer questions about the Leland Systems;.  If you need

help, contact the consultants on the second floor of Sweet Hall at 725-

2101, or send a message to the electronic mail address consult@leland.







Part III: Working With Files and Directories

============================================



About Part III:  The first three sections of Part III show you how to

create and organize UNIX files and directories.  A file is a data set,

such as a chart or an essay, that is saved under a particular title.

You can open a saved file at any time to edit or print its contents.

All work you do while using a UNIX system must be saved to a file or it

will be lost when you log out.  When you open a particular file, all

commands you issue will apply to that file, unless you specify

otherwise.



Directories are basically "folders" used to organize files and other

directories.  When no files are open, all commands you issue will

operate on the directory you are currently in unless you specify

otherwise.  Once you are logged in to your account, you will need to

navigate among the directories to find the files and programs you want

to use.



The last two sections of Part III explain the procedures for securing

your files and directories.  UNIX gives you the ability to protect your

work as you see fit.  You decide what you can do to your work, and what

others can do to it.  The UNIX security system allows you some control

over who can see, alter, and use your files and directories.







Managing Directories

--------------------



Directories and files are organized hierarchically, in the shape of an

inverted tree.  Below is a diagram of a simplified filesystem.

Directories are represented with a slash (/).



                                   /

                                   |

               --------------------------------------------

               |          |                    |          |

              usr/       etc/               student/     ps/

               |                               |          |

          ------------                    ------------  faculty/

          |          |                    |          |

        class/      adm                jones/      barney/

          |                               |          |

     ------------                    ------------   work

     |          |                    |          |

  cs240a      cs243             docfiles/   datafiles/

                                   |

                              ------------

                              |          |

                         sample.doc   other.doc





Most of the examples in this section use the directories and files

listed in this diagram.





The Root Directory:  The / at the top of the diagram is the root

directory for the filesystem as a whole.  This sample root directory

contains four other directories, usr, etc, student and ps.  Such

directories-within-a-directory are called subdirectories.  Every file on

the system is contained directly or indirectly (through a subdirectory)

in the root directory.





Your Home Directory:  When you first login to a UNIX system, you are

initially in your home directory, the directory that holds your personal

files.  In the diagram above, the home directory of the user named Jones

is /student/jones.  Because of the large number of accounts on the

Leland Systems, actual home directories have longer names and are more

deeply nested.  A student account rjones may have a home directory like

/s7/r/rjones or /afs/ir/users/r/rjones.





Your Working Directory:  Whenever you use a UNIX system, you are working

within a specific directory.  That directory is your working directory.

For example, if you were in the /jones directory in the diagram, your

working directory would be /student/jones.  Because most commands that

operate on directories will affect your working directory (unless you

specify otherwise), it's important to know what the working directory

is.  To find out, use the pwd (print working directory) command:



elaine24> pwd                       Prints the working directory, that

                                    is, lists the name of the working

/student/jones                      directory on the screen.





Creating a Directory:  You can create a new directory at any time with

the mkdir command.  When you use this command, a new directory with the

specified name will appear within your working directory.  (You may want

to distinguish your directory and file names so you can differentiate

them easily.  One method is to begin each directory name with an

uppercase letter and each file name with a lowercase letter.)



elaine24> mkdir Test                Creates a directory named Test in

                                    the working directory.





Moving Among Directories:  You can move from one directory to another

with the cd (change directory) command, using the name of the new

directory as the argument.  When you use the cd command with no

argument, you move directly to your home directory.





elaine24> cd docfiles               Changes from the current working

                                    directory (jones) to docfiles, which

                                    becomes the new working directory.

elaine24> pwd

/student/jones/docfiles



This method lets you move down one directory, that is, from the working

directory to one of its subdirectories.  To move up one directory, use

.. (two periods) as the argument to cd.



elaine24> cd ..                     Changes to the directory one level

                                    above, in this case back up to

                                    jones.

elaine24> pwd

/student/jones



To move further than one level at a time, you must list each directory

along the way, separating them by slashes.



elaine24> cd /jones/docfiles        Changes directory from student to

                                    docfiles, two levels below.

elaine24> pwd

/student/jones/docfiles



elaine24> cd ../datafiles           Moves back up one level to jones,

                                    and then down to datafiles, a

                                    directory that is parallel to

                                    docfiles.

elaine24> pwd

/student/jones/datafiles





Removing a Directory:  You remove a directory with the rmdir (remove

directory) command, using the directory name as the argument.  This

command will not work if there are any files or other directories within

the directory you wish to remove.



elaine24> rmdir docfiles            The directory docfiles is removed

                                    from the working directory.





If you wish to remove a directory and all of its contents, use the

option -r.  Make sure that you actually want to delete everything in

this directory before you execute this command!



elaine24> rmdir -r docfiles         docfiles is removed, along with

                                    everything inside it.  Use with

                                    caution!  The advantage is that you

                                    don't have to empty the directory

                                    first.





Displaying a Directory's Contents:  The ls command lists the files and

subdirectories contained in the specified directory.  As shown in the

following sample sessions, different information displays depending on

what arguments and options you use.



elaine24> ls                        Lists the names of files and

Air   Class   Mail   a.out   bin    subdirectories in the working

                                    directory.  UNIX alphabetically

                                    orders files and directories with

                                    initial uppercase letters first,

                                    then with initial lowercase letters.



elaine24> ls /usr                   Lists the names of files or

2020       crash      ingres        subdirectories in a directory other

adm        dict       kernels       than the current one, in this case

athena     doc        lib           /usr.

bin        etc        local

blss       field      lost+found



elaine24> ls -l                                    Using ls with the -l

drwx------  4 tsoi      512 May 16 08:36 Air       option lists each

drwx------  9 tsoi      512 May 11 10:49 Class     file or directory in

drwx------  9 tsoi     1024 May 19 13:36 Mail      the working

drwx------  9 tsoi      512 May 11 10:49 a.out     directory, along with

drwxr-xr-x  3 tsoi      512 May 18 23:46 bin       its permissions

                                                   (security informa-

                                                   tion), creator, size

                                                   in bytes, and date of

                                                   last modification.





elaine24> ls -F                             Lists what's in the working

Air/   Class/   Mail/   a.out*   bin/       directory, specifying the

                                            file types.  The character /

                                            after a name indicates a

                                            directory; * indicates a

                                            program you can run.





elaine24> ls -a                     Lists all files, including dot

.cshrc        .logout     a.out     files.  (Dot files are explained

.forward      .plan       bin       below, under Managing Files.)

.login        Class       mail







Managing Files

--------------



Viewing Files:  You can use the more, less and page commands to display

a file's contents one screenful at a time.  To display the next

screenful, press the space bar.  All three commands scroll the text as

they display the next screenful.  To learn the differences among these

commands, type man more, man page, or man less as appropriate.



elaine24> more longfile             Scrolls the contents of the file

                                    longfile, screen by screen.

              Press the space bar to display the

                                    next screenful.  To return to the

                                    prompt, use C-c command.



Sometimes you might like to see just a few lines at the top or bottom of

a file in order to check on its contents.  The head command displays the

first ten lines of a particular file, and the tail command displays its

last ten lines.  Both allow you to specify the exact number of lines to

display with the -n option (where n is the number of lines to display).



elaine24> head todo.list            Displays the first 10 lines of the

                                    file todo.list.

TODO LIST: 1. wash cars

           2. put out trash

           :

          10. deposit check





elaine24> tail -5 todo.list         Displays the last 5 lines of the

                                    file todo.list.

      13. reserve tennis court

      :

      17. write up documentation





Moving and Renaming Files:  The mv command either gives a file a new

name or moves it to a new location.  Its first argument is always the

file you are moving or renaming.  Its second argument is the destination

directory (the directory where the file should be moved), along with the

new name of the file.  If only a directory is given as the second

argument, the file is moved into that directory with the same file name.

If only a new filename is given, the newly named file stays in its

current directory.





elaine24> mv mbox Oldmail           Moves the file mbox into the

                                    directory Oldmail.



elaine24> mv supplies toget.list    Gives the file supplies the new name

                                    toget.list.



elaine24> mv mbox Oldmail/xbox      Moves the file mbox into the

                                    directory Oldmail, and changes its

                                    name to xbox.





Copying Files:  The command to copy files is cp.  It functions in

exactly the same manner as mv.  The only difference is that it creates a

duplicate of an existing file, leaving the original file untouched.  It

helps to give the new file a different name from the original file in

order to avoid confusion.



elaine24> cp mbox xbox              In the working directory, creates a

                                    copy of the file mbox and calls it

                                    xbox.



elaine24> cp mbox Oldmail/xbox      Copies the file mbox from the

                                    working directory to the Oldmail

                                    directory, and calls the new file

                                    xbox.





IMPORTANT NOTE

--------------



When copying, moving or renaming a file, make sure that no other file

with the same name already exists in the destination directory.  UNIX

does not warn you if you are using the same name for two different

files.  If you try to place a file in a directory where another file

with that name exists, the old file will be permanently removed and

replaced by the new file.





Removing Files:  The command rm removes files permanently.  To be safe,

use the option -i with the rm command and the computer will ask if

you're sure you want to remove the file before proceeding.



elaine24> rm junk.old               Removes the file junk.old

                                    permanently.



elaine24> rm -i test.doc            Removes the file test.doc; the

                                    computer asks for confirmation.

rm: remove test.doc? y              You type y for yes or n for no.





Dot Files:  Within your home directory are several files whose names

begin with a dot (or period).  Most users don't need to access dot files

often.  They don't appear when you issue the ls command (unless you use

the -a option).  You can create and remove dot files in any directory

just as you can normal files.



     Some Common Dot Files:



.cshrc file     The system runs the commands in this file each time you

                start a shell.  Usually a good place for alias commands.

                See Customizing Your Session on page 15.



.login file     The system runs the commands in this file when you

                login.  See Customizing Your Session on page 15.



.plan           Optional files you create that contain personal or work-

                related information of an arbitrary nature that is

.project        displayed when your username is fingered.  See Finding

                Out About Other Users on page 25.







Advanced Procedures

-------------------



Absolute and Relative Pathnames:  Pathnames give the locations of the

files and directories you refer to in your command statements.  They act

as road maps, telling the computer exactly where to go to find the

information you need.  The absolute pathname tells where something is in

relation to the root directory of the filesystem, listing every

subdirectory along the way.  For example, the absolute pathname for the

file sample.doc from the diagram on page 6 is

/student/jones/docfiles/sample.doc.



Just as absolute pathnames use the root directory as their reference

point, relative pathnames use the working directory as their base.

Relative pathnames give directions to a directory or file according to

its location in relation to the working directory.  Using the same

diagram, if you are in the jones directory and wish to refer to the file

sample.doc, you would use the pathname that gives the file's location

relative to the jones directory, docfiles/sample.doc.  Relative

pathnames are useful in complicated filesystems with deeply nested

directories and files.  Note that relative pathnames never begin with /

because their origin is the working directory and not the root

directory.



The following examples are also based on the diagram on page 6.





elaine24> pwd                       The working directory is docfiles.

/student/jones/docfiles



elaine24> cp other.doc ../datafiles Copies other.doc to the directory

                                    datafiles, using its relative

                                    pathname.  It would have been more

                                    troublesome to use the absolute

                                    pathname, which is

                                    /student/jones/datafiles



elaine24> pwd                       The working directory is barney.

/student/barney



elaine24> cp work /ps/faculty       Copies the file work to the

                                    directory faculty, using the

                                    absolute pathname.  In this case, it

                                    would have been more troublesome to

                                    use its relative pathname,

                                    ../../ps/faculty.





Periods as Shorthand:  In the cases when you want to use the working

directory as an argument for a command, you can use a period as the

shorthand term for it.  If the working directory is /ps/faculty, you

could refer to it with . in the argument to the copy command cp.



elaine24> cp /student/jones/docfiles/sample.doc .  Uses the absolute

                                                   pathname of the file

                                                   sample.doc to copy it

                                                   to the working

                                                   directory, referred

                                                   to with a period.



As stated earlier, .. (two periods) is used to refer to the directory

one level above the working directory.





Referring to Groups of Files:  The shell recognizes some special

characters associated with  file names.  Use these characters to specify

groups of files easily.



The Character                       What It Means

-------------                       -------------



*                                   refers to any string of characters.



?                                   refers to any single character.



~                                   has special meaning when associated

                                    with a username as in ~jones.  In

                                    these cases this refers to the user

                                    jones' home directory.  Thus,

                                    ~jones/.login refers to the file

                                    .login in jones' home directory.

                                    Also, you can use ~ to refer to your

                                    home directory.



[ ]                                 indicates any single characters

                                    included in the brackets.





Examples



elaine24> ls *.c                    Lists all files whose names end with

disk.c   drum.c   main.c            .c.



elaine24> ls d*.c                   Lists all file names beginning with

disk.c   drum.c                     d and ending with .c.



elaine24> ls main.?                 Lists all files beginning with main

main.c   main.h                     and ending in any single character.



elaine24> ls *.[ch]                 Lists all files ending in either .c

disk.c     globals.h                or .h.

disk.h     main.c

drum.c     main.h

drum.h



elaine24> ls ~jones                 Lists all files in the home

Work   mbox   bin                   directory for jones.





Transferring Files Between Computers:  The FTP Program allows you to

send or receive copies of files to or from another computer.  It is

available on all of the Leland Systems; and on most microcomputers and

workstations connected to SUNet.  (The FTP Program may not work on all

systems if you have an AFS account.)



The following instructions explain how to transfer files between UNIX

hosts.  The ftp command takes the remote computer name (the name of the

other computer involved in the transfer) as its argument.  You initiate

an FTP transaction by identifying yourself to the remote computer with

your username and password on that system.  (To use anonymous FTP, type

anonymous as the username and your username as the password.)  You can

then move to any directory on the remote computer with the cd command.

Use the command send to transfer a file from your computer to the remote

computer.  The file you wish to transfer must be in your working

directory; it will appear in the directory you have specified in the

remote computer.  Use the command get to transfer a file from the remote

computer to your computer.  The file you wish to receive must be in the

working directory of the remote computer; it will appear in your working

directory.  Leave the FTP program with the command quit; the normal

system prompt reappears.



elaine24> ftp jessica               Initiates file transfer with the

Connected to jessica.stanford.edu.  remote computer Jessica.



220 jessica.stanford.edu FTP server (Version 4.169 Fri May 26 12:12:25

PDT 1989) ready.

Name (jessica:kath): ksteele        Requires the username for your

                                    account on Jessica.

Password (jessica:ksteele):         Requires the password for your

                                    account on Jessica.

331 Password required for ksteele.

230 User ksteele logged in.

ftp> send SOC22                     Copies the file SOC22 from your

                                    computer to the remote computer.

200 PORT command successful.

150 Opening ASCII mode data connection for SOC22.

226 Transfer complete.

local: SOC22 remote: SOC22

56970 bytes sent in 0.84 seconds (66 Kbytes/s)

ftp> get SOC23                      Copies the file SOC23 from the

                                    remote computer to your computer.

200 PORT command successful.

150 Opening ASCII mode data connection for SOC22 (55706 bytes).

226 Transfer complete.

local: SOC23 remote: SOC23

56970 bytes received in 0.86 seconds (65 Kbytes/s)

ftp> quit                           Ends the FTP program.

221 Goodbye.

elaine24>







Non-AFS Security

----------------



Note:  The information on UNIX file access permissions does not apply to

AFS-based accounts.  Likewise, the information on AFS access control

lists does not apply to non-AFS accounts.  There are some exceptions,

such as the directory /tmp.  On all systems, /tmp is governed by non-AFS

file access permissions.  Be sure to refer to the section that applies

to you.



Users:  In the UNIX environment, those who may access a particular file

or directory are divided into these three classes:



owner     the user who owns the file or directory



group     the group of users who share access to a file.  (Every user

          belongs to a group.  In general, students all belong to the

          student group.  To see what group you are in, type groups at

          the system prompt.)



other     all other users



Access Permissions:  When you create a file or directory, it is assigned

a default set of permissions that control access to it.  You can change

these permissions.  For each class of users, the following three

permissions may be granted for each file or directory:



Permission     File                          Directory



read (r)       Allows you to read the file.  Allows you to list the

                                             files and subdirectories in

                                             the directory.



write (w)      Allows you to create, delete  Allows you to create and

               and modify the file.          delete files in the

                                             directory, since this

                                             requires writing to the

                                             actual directory.



execute (x)    Allows you to run a file.     Allows you to list only the

                                             files whose names you

                                             specify, not the directory

                                             itself.  Therefore, you can

                                             list only the files whose

                                             names you know.  For

                                             example, if the directory

                                             tmpdir had execute

                                             permission only and you

                                             typed ls -l tmpdir, you

                                             would get no result.

                                             However, if you typed

                                             ls -l tmpdir/workfile,

                                             information about workfile

                                             would be displayed.



Displaying a File's Permissions:  With the command ls -l, you can see

the permissions associated with a particular file as the first 10

characters on each line.



elaine24> ls -l

drwxrwxr-x     5     tsoi     512     Feb 23 09:30 MyPublicDir

-rw-r-----     5     tsoi     512     Feb 22 14:30 intro.unix

-rwxr-xr-x     5     tsoi     512     Feb 22 16:30 a.out



The first character indicates whether this file is a directory (d) or

just a regular file (-).  The next nine characters are three groups of

three characters each.  These are the permissions granted for the owner,

group, and other user classes, respectively.  A permission is granted if

the letter is present, and not granted if a hyphen is there instead.

Thus, in the example above, the file intro.unix is a regular file (-)

that allows the owner reading and writing privileges (rw-), but limits

the group to reading privileges only (r--).  Other users are not allowed

to do anything with this file (---), and execution privileges are not

allowed for any class of users.





Note that even if another user has access to a particular file, he or

she will be unable to use such privileges if they do not have access to

the directory in which the file is located.  Be sure to grant such

access to all of the directories in a file's path that are under your

control.



Making Security Changes:  You can change the permissions associated with

a file with the chmod command.  Users are identified by letters when you

use chmod:  the owner is u, the group is g, others are o, and a

represents all users.  You literally add or take away permissions with

the + and - signs.  The file which you are securing is the command's

final argument.security changes



elaine24> ls -l

total 3

-rwx------     1     tsoi     40234     May 23 14:50 myunix.doc

-rw-rw-rwx     1     tsoi       645     May 23 14:20 script

-rw-r-----     1     tsoi       974     May 23 09:24 xcomments

elaine24> chmod a+r myunix.doc      Grants read access to all (a).

elaine24> chmod a-w script          Denies write access to all.

elaine24> chmod g+w xcomments       Grants write access for the group

                                    (g).

elaine24> chmod u+x,o-x script      Grants execute right for the owner

                                    (u), and removes execute right for

                                    other (o) class.





elaine24> ls -l

total 3

-rwxr--r--     1     tsoi     40234     May 23 14:50 myunix.doc

-r-xr--r--     1     tsoi       645     May 23 14:20 script

-rw-rw----     1     tsoi       974     May 23 09:24 xcomments

elaine24>



Security Changes Shortcut:  You can also use a three digit number

argument to the chmod command in order to accomplish changes in

permissions in fewer steps.  The three digits of the argument, for

example, 421, specify the owner's (4), the group's (2) and the other

users' (1) permissions respectively.  Each digit in the argument is a

sum of a possible three numbers corresponding to the access privileges

granted to that user class:



read access     add 4 to sum



write access    add 2 to sum



execute access  add 1 to sum



For example, if you wanted to grant read and write access for one of the

user classes, you would add the read access value, 4, to the write

access value, 2, and get a result of 6.  This would be the digit you

would use in the appropriate place (for the correct user class) in the

three digit number in the chmod command.



elaine24> chmod 644 .login          The owner can read and write;

                                    everyone else can only read.

elaine24> ls -l .login

-rw-r--r--  1 tsoi       796 May  7 18:11 .login



elaine24> chmod 740 myscript        Lets the owner read, write and

                                    execute; lets the group read; grants

                                    no privileges to others.

elaine24> ls -l myscript

-rwxr-----  1 tsoi      356 May  7 10:30 myscript







AFS Security

------------



Many Leland Systems accounts, including all Power and Wisdom accounts,

are AFS-based UNIX accounts (as opposed to NFS-based accounts).  (If the

pwd command says your home directory is in /afs/ir, you have an AFS

account.)  AFS is a method by which different computers may share the

same files, conserving disk space and making a wider variety of

computers available to each user.  If your account is an AFS-based

account, you have additional control over exactly what type of access

you wish to give to individual users or groups of users on your system

or on other AFS-based systems.  Eventually, all Leland Systems accounts

will move to AFS.



Note:  The information on UNIX file access permissions does not apply to

AFS-based accounts.  Likewise, the information on AFS access control

lists does not apply to non-AFS accounts.  There are some exceptions,

such as the directory /tmp.  On all systems, /tmp is governed by non-AFS

file access permissions.  Be sure to refer to the section that applies

to you.  File permissions for owner are always governed by non-AFS

rules.



Access Rights:  Each directory in AFS has an Access Control List (ACL)

associated with it.  The ACL grants different users or groups of users

different types of access rights for the files contained in the

directory.  As the owner of a directory, you may determine precisely

which rights you grant to which users.  The seven access rights and

their one letter codes are:



(r)     Read allows a user to read the contents of any file in the

        directory.  Files that are meant to be private must be placed in

        a separate directory or subdirectory.



(w)     Write allows a user to modify the contents of any existing file

        in the directory.



(k)     Lock allows a user to flock a file.  Certain programs use this

        method to ensure that two processes do not try to write to the

        same file at the same moment.



(l)     Lookup allows a user to list the names of the files and

        subdirectories in a directory, and to examine the ACL for a

        directory.  Lookup also controls access to subdirectories.  For

        a user to have access to a subdirectory, she must have the

        Lookup right for its parent directory.  Note that Lookup does

        not allow a user to read the contents of a file in the

        directory.



(i)     Insert allows a user to add new files to the directory and to

        create new subdirectories.  It does not allow the user to change

        the contents of existing files in the directory.



(d)     Delete allows a user to remove files and subdirectories from a

        directory.



(a)     Administer allows a user to change the ACL for a directory.

        Users always have this right for their home directories and

        their subdirectories, even if they remove themselves from the

        ACLs.



Examining the ACL for a directory:  You must have the Lookup right for a

directory to be able to examine its ACL.  Use the fs listacl command to

examine the access control list for a given directory.  Here we examine

the ACL for the current directory, ".":



power-[1> fs listacl .

Access list for . is

Normal rights:

  system:anyuser rl

  rjones rlidwka

power-[2>



This indicates that any user may list the contents of this directory and

read the files in the directory.  The user rjones has all access rights

for the directory.  This is the default ACL for the user rjones' home

directory on many AFS systems.  On some systems (including Power and

Wisdom), system:anyuser is granted only the Lookup right.  This way, the

contents of the files in a user's home directory are hidden from other

users.



The regular UNIX access permissions for a file or directory may be

viewed using the command ls -l.  However, these UNIX access permissions

have very little effect on user access to the file or directory.  AFS

file access rights override UNIX permissions in most cases.





Making Security Changes:  The fs setacl command allows a user to change

the ACL for any directory for which he or she has the Administer right.

In the following sample session, the user rjones creates a project

subdirectory, and grants two other users, buzz and pjames, the (l)

Lookup, (r) Read and (i) Insert rights.security changes



power-[2> fs listacl .

Access list for . is

Normal rights:

  system:anyuser l

  rjones rlidwka

power-[3> mkdir project                Creates project directory.

power-[4> fs listacl project

Access list for project is

Normal rights:                         Note that the project directory

  system:anyuser l                     was, by default, created with the

  rjones rlidwka                       same ACL as its parent directory.

power-[5> fs setacl project buzz rli   Grants Read, Lookup, and Insert

power-[6> fs setacl project pjames rli rights to buzz and pjames for the

power-[7> fs listacl project           project directory.

Access list for project is

Normal rights:

  system:anyuser l

  buzz rli

  pjames rli

  rjones rlidwka



Before giving buzz and pjames access rights to the project directory in

the example above, rjones first verified that all users had the Lookup

right for his home directory.  Remember, without the Lookup right for a

directory, users cannot access any of that directory's subdirectories,

regardless of how the ACLs are set for those subdirectories.







Part IV: The Shell Program

==========================



About Part IV:  As soon as you log in, the shell program activates.

Providing the interface between you and the UNIX system, the shell is

the program that reads your commands and invokes other programs to carry

them out.  The first section of Part IV teaches you how to customize

your shell environment.  The second section describes how to maneuver

the input and output (I/O) of your commands in the shell environment in

order to access files and issue commands more effectively.  The third

section explains how to handle multiple jobs at once.  (A job is the

process you set in motion when you issue a command.)  The final section

describes command histories and how you can use them.







Customizing Your Session: Defining Your Shell Environment

---------------------------------------------------------



About the Shell Program:  The shell program used on all Leland Systems

computers is the tcsh shell.  (You can obtain full documentation about

this shell with man tcsh.)  You invoke the shell program when you login;

it displays the system prompt when it is ready for your input.

Throughout your UNIX session, the shell program acts as a liaison

between you and the computer, translating your commands so the computer

can execute them, and translating the computer's output so you can

understand it.



The first time you invoke the shell program, it is called your login

shell.  To leave the login shell, you use the logout command.  During a

work session, you may invoke the shell program again when you use

certain commands, e.g., script.  A change in the default prompt may

indicate that you have invoked the shell program again.  To leave a

shell that is not the login shell, use the exit command.





Setting Shell Variables:  Shell variables help to determine how the

shell program interacts with you.  You can create your own shell

variables and assign them values with the set command.  You can then use

the variable in a command line by prefixing the variable name with the $

symbol.



elaine24> set workdir=/student/jones/Work   Creates the variable workdir

                                            to represent the directory

                                    /student/jones/Work.  You must use

                                    its absolute pathname.



elaine24> echo $workdir             Shows the value assigned to workdir.

                                    /student/jones/Work



elaine24> cd $workdir               Changes from the working directory

                                    to the workdir.



elaine24> unset workdir             Removes the shell variable workdir.

Now, you can no longer

                                    use workdir to refer to

                                    /student/jones/Work.



The procedure shown in the preceding sample session sets the shell

variable for your use during your interaction with the current shell

only.  Therefore, if you were to use the script command, you would

invoke a new shell; the shell variable you just set would not apply to

this new shell.  Also, the next time you login you will be interacting

with a new shell and will have to reset any shell variables you want to

use.



Shell Variables and the .cshrc and .login Files:  To set shell variables

so that they are available every time you login, you must add them to

your permanent .login file; to use shell variables every time you

interact with a new shell, add them to your .cshrc (C Shell Runtime

Commands) file .cshrc file.  Both of these dot files are located in your

home directory.  The default .login and .cshrc files for the UNIX

systems are located in the directory /usr/skel.  (See Managing Files on

page 8 for more information on dot files.)



To add command lines to your .cshrc and .login files, use a text editor.

(See Part V for information on the EMACS text editor.)  Insert the

command line set shell variable = its value.  You can change or delete

the shell variable at any time with a text editor.



The commands you add to these files will activate when you next login.

To invoke the commands in your .cshrc or .login files immediately, use

the source command:



elaine24> source .login             Runs the commands in the .login

                                    file.  The shell variables are set

                                    as you specified in the .login file.



elaine24> source .cshrc             Runs the commands in the .cshrc

                                    file.  The shell variables are set

                                    as you specified in the .cshrc file.



Looking at Shell Variable Settings:  You can use the set command with no

arguments to see all currently operating shell variables and their

values.



elaine24> set                       Displays current shell variables and

                                    their values.

argv     ()

cwd      /student2/tsoi

filec

history  20



Changing the Prompt:  The value for the prompt shell variable is what

displays as the shell's prompt.  You can customize your shell prompt by

using the procedure shown in the following sample session.



elaine24> set prompt="what now?"    Changes the shell prompt from

                                    elaine24> to what now?

what now?                           Notice quotation marks are used to

                                    enclose more than one word.





To set the prompt automatically for later shell interactions, use a text

editor to change or add the command line set prompt="the desired prompt"

in your .cshrc file.





Setting Your Terminal Type Automatically:  The value associated with the

term shell variable is the type of terminal you are using.  This shell

variable must ordinarily be set each time you begin a work session,

because programs such as text editors must know what kind of terminal

you're using in order to display information on your terminal screen

properly.  You can add the command line set term = your terminal type to

your .login file.  (See page 4 for a list of terminal types.)





Setting Your Search Path:  One important shell variable is the path

shell variable, which is a list of directories enclosed in parentheses.

This list of directories is your search path; UNIX will search in these

directories for a program that you specify in a command line if you do

not use its absolute or relative pathname.  Therefore, if a program is

in your search path, you can type just the name of the program, without

a pathname.



For example, suppose your search path is (/bin /usr/local/X/bin

/usr/bin).  When you type a program name or command, the shell looks

first in the /bin directory, second in the directory /usr/local/X/bin,

and third in the directory /usr/bin.  It keeps looking until it either

finds the program or command with the specified name or finishes looking

through all the directories in your search path.



elaine24> teachemacs                teachemacs begins a tutorial on

                                    EMACS.

teachemacs: command not found.      The command is not in the search

                                    path.



elaine24> set path=($path /usr/local/bin)   Adds the directory where

                                            teachemacs is located to the

                                            search path.



If you find that you often use a program or command not specified in

your search path, edit or add the command line set path=(the directories

to comprise your search path) in your .cshrc file.





The History Shell Variable:  The history shell variable is a number.

This is the number of command lines UNIX will display when you use the

history command.  (See Keeping Command History on page 21.)  To set the

number of commands that UNIX will save for subsequent sessions, use a

text editor to insert or change the command line set history = number

(of commands to be saved) in your .login file.





Environment Variables:  Environment variables are similar to shell

variables, but other programs besides the shell use their values.

Typically, these environment variable names are all uppercase, such as

PRINTER, which determines the default printer.  The commands to set,

unset, and look at environment variables are slightly different than

those used with shell variables.  Like shell variables, the command

lines can be changed or added to your .login or .cshrc files with a text

editor.  environment variables



elaine24> setenv PRINTER sweet0     Sets environment variable PRINTER to

                                    the printer sweet0.



elaine24> unsetenv PRINTER          The environment variable PRINTER is

                                    no longer set to sweet0.

                                    Returns to the default printer.



elaine24> printenv                  Displays environment variables and

HOME=/user/tsoi                     their values.

SHELL=/bin/csh

TERM=z19

USER=tsoi





About Aliases:  Aliases allow you to create shorthand names for

frequently used or lengthy command lines.  When the alias appears in the

command line that the shell reads, its text is replaced by the

definition of the alias.  Use the alias command to create aliases and

the unalias command to delete aliases.aliases



elaine24> alias sw0 lpr -Psweet0    sw0 will be shorthand for printing

                                    on the sweet0 printer.



elaine24> alias sw0                 Shows commands associated with sw0.

lpr -Psweet0



elaine24> alias                     By itself, alias displays the

ls ls -F                            aliases you set up.

rm rm -i

sw0 lpr -Psweet0



elaine24> sw0 unix.doc              Prints file unix.doc on the sweet0

                                    printer.



elaine24> unalias sw0               Removes the alias sw0.



If you know you want to use the alias in later interactions with the

shell program, you should add the command line to your .cshrc file.







Re-Directing I/O and Building Pipes between Commands

----------------------------------------------------



Input/Output (I/O):  Normally, UNIX commands needing user input require

you to type the input at the keyboard.  Most UNIX commands show you the

output of the command by displaying it on your terminal screen.  The

keyboard is the standard input, and the terminal is the standard output.

But often you might like to store the lengthy output of a command in

another file or cause the input for a command to come from a specific

file.  The shell provides a means for redirecting where a command sends

its output or receives its input.  The characters <,  > and >> are used

to redirect input and output.input and output (I/O)



elaine24> elm rjones < letter       Mails the contents of the file

                                    called "letter" to user rjones.



elaine24> who                       who shows who is logged on to the

                                    system.



tsoi    ttyr0  May 17 19:11  (tip-sweetc.stanf)

andrew  ttyr1  May 17 19:03  (pinch.stanford.e)

jester  ttyr3  May 17 15:32  (tip-cerasa.stanf)



elaine24> who > who.doc             Places the output of who command

                                    into the file who.doc.  If the file

                                    already exists, its contents are

                                    replaced by the output of the who

                                    command.  If the file does not

                                    already exist, it is created.



elaine24> who >> info.doc           Appends the output of the command

                                    who to the end of file info.doc.

                                    The contents of this file remain

                                    intact with the output of the who

                                    command attached at the end.





IMPORTANT NOTE

--------------



In the sample session above, the output of who was placed in the file

who.doc.  When you re-direct the output of a command to a file that

already exists, the contents of that file will be replaced by the re-

directed output.  To avoid accidentally overwriting an existing file

with the > character, use the text editor to put the command set

noclobber in your .cshrc file.







Concatenating Files:  By using the cat command, you can string files

together.  The cat command displays the files you specify as arguments.

Its standard output appears on the screen of your terminal.  But with

the > character, you can re-direct the output from the screen to another

file.  Note the warning in the paragraph above.



elaine24> cat pt1.doc pt2.doc > fullbook      Concatenates pt1.doc and

                                              pt2.doc into the new file

                                              fullbook.



Pipes:  Often it is convenient to make the output of one command become

the input of another command.  The UNIX shell provides a means of

connecting the output and input of two commands via a mechanism called a

pipe.  The pipe character | is placed between two commands when the

first command's output should be the input of the second.



elaine24> cat pt1.doc pt2.doc | more          Concatenates two files

                                              into one, and displays the

                                              new file one screenful at

                                              a time (the command more).



tsoi    ttyr0  May 17 19:11  (tip-sweetc.stanf)

andrew  ttyr1  May 17 19:03  (pinch.stanford.e)

jester  ttyr3  May 17 15:32  (tip-cerasa.stanf)



elaine24> ls | lpr -h               Prints (lpr) the contents of the

                                    working directory (ls), suppressing

alpha     gamma                     the header page (-h).

beta      omega



More about Characters:  The characters in the command line that redirect

input/output (<, >, and >>) and the pipe character (|) are not parts of

the commands themselves.  Rather, they are characters that hold special

meaning to the shell.  That is, the commands know nothing about the >,

<, and | characters, but the shell recognizes them and provides the

mechanism by which this redirection takes place.







Controlling Jobs

----------------



Foreground and Background Jobs:  Because UNIX is multi-tasking, you can

run more than one process or job at a time.  If a job is actively

communicating with your terminal, it is running in the foreground.  If

you have started other jobs that are still running but not actively

communicating with your terminal, they are in the background.



Normally, when you begin a job by typing a command at the prompt, it

runs in the foreground.  If it is lengthy, however, you may want to keep

your terminal free so you can work on something else while the first job

is underway.  To begin a job in the background instead of the

foreground, type the & character at the end of the command line:



elaine24> sort bigfile > big.out &  sort alphabetizes the contents

                                    bigfile.  Places the output

[1] 9254                            into big.out.  The & character

                                    specifies the job should take

elaine24>                           place in the background.



In this sample session, the [1] is the job number, and 9254 is the

process identifier (PID) for that job.  Notice the prompt immediately

returns.  When the job is finished, the system displays a message that

tells you it has finished executing your command.  (To receive immediate

notification, place the shell command set notify in your .cshrc file.)



A Note About AFS:  Many Leland Systems accounts (including all Power and

Wisdom accounts) are AFS-based UNIX accounts (as opposed to NFS-based

accounts).  (If the pwd command says your home directory is in /afs/ir,

you have an AFS account.)  AFS is a method by which different computers

may share the same files, conserving disk space and making a wider

variety of computers available to each user.  Because of the increased

file security offered by AFS, extremely long login sessions and

extremely long-running background jobs (longer than 25 hours) may be

problematic.  For information on how to successfully run programs

requiring more than 25 hours of real time, contact a consultant at 725-

2101 or send electronic mail to consult@leland.



Finding Out What Jobs Are Running:  You can check on the status of your

jobs by using the jobs or the ps command:



elaine24> spell intro.doc > misspell &     The character & specifies

                                           that this spell job should

                                           take place in the background.

[1] 9244                                   Its job number is [1] and the

                                           process identifier is 9244.



elaine24> ls /usr/bin > binlist &          This ls job will also take

                                           place in the background.  Its

[2] 9300                                   job number is [2] and the

                                           process identifier is 9300.





elaine24> who | more                Displays who's using the system, by

                                    screenful.



^Z                                  ^Z indicates you stopped the job

                                    with C-z.

Stopped



elaine24> jobs                      jobs shows status of jobs, by job

                                    number.



[1]     - running     spell intro.doc > misspell     Jobs 1 and 2 are

                                                     running; job 3 is

                                                     stopped.

[2]     running     ls /usr/bin > binlist

[3]     + stopped     who | more



elaine24> ps                        ps shows status of jobs, by process

                                    identifier (PID).  STAT is

 PID TT STAT  TIME COMMAND          job status: R=running, S=sleeping,

                                    T=stopped.

6964 p4 S     0:03 -csh (csh)       This is your original shell.

7824 p4 R     0:00 ps               ps is the command running in the

                                    foreground.

7213 p4 R     0:01 spell            spell is a command running in the

                                    background.

7345 p4 R     0:02 ls               ls command is also running in the

                                    background.

5233 p4 T     0:00 who              The who command stopped; note the

                                    T under STAT.

5235 p4 T     0:00 more             The more command that was part of

                                    the who command also stopped.  For

                                    more information on what these

                                    fields mean, issue the command man

                                    ps.





Stopping a Background Job:  To stop a job running in the background, use

the stop command.  You can use the bg command to continue the stopped

job.  If you still have stopped jobs when you log out, a message will

provide a reminder.  Although it is not recommended, you can choose to

ignore the message and type logout again.  Instead, you should use the

jobs command to review the suspended jobs and then either use the bg

command to continue them or the kill command to eliminate them

altogether.





Continuing and Moving Jobs:  The command bg with no arguments continues

the most recently stopped background job where it left off.  If you want

to continue a specific job you can type bg %job number.  For example, to

continue job number 5, type bg %5.  The command fg moves a job running

in the background to the foreground.  To move job number 5, you would

type fg %5.



elaine24> bg                        The command bg resumes the job.

                                    It now continues in the background.

[1]  ls /student1 > studentlist &   The number for this job is [1].



elaine24> jobs                      The jobs command shows job 1 is

                                    running.



[1]  Running     ls /student1 > studentlist



elaine24> fg %1                     The fg command brings a job

                                    currently running in the

ls /student1 > studentlist          background to the foreground.  You

                                    specify which job with the %

                                    character and the job number.





Killing a Background Job:  To stop a job running in the background when

you are sure you don't want to finish it later, use the kill command.

You cannot resume any job that you have killed.  Specify the job to stop

or kill by either its job number or its process identifier (PID).  A

message appears stating that the job has been killed or terminated.  If

it does not appear, repeat the kill command or type kill -9 (an emphatic

kill).

elaine24> sort bigfile > big.out &       The & character specifies that

                                         this sort job should take place

[1] 7983                                 in the background.  Note job

                                         number and PID.



elaine24> ls /student1 > studentlist &   This ls job will also take

                                         place in the background.  Note

                                        job number and PID.

[2] 9254





elaine24> stop %1                   Stops the process running with job

                                    number 1.



[1] + Stopped (signal)  sort bigfile > big.out



elaine24> kill 9254                 Kills the process running with PID

                                    9254.



[2]   Terminated   ls student1 > studentlist     The message confirms it

                                                 has been terminated.



elaine24> kill -9 %1                Kills the process running with the

                                    job number 1.

                                    This is an emphatic kill.







Keeping Command History



Reviewing Your Commands:  The shell has a mechanism that allows you to

review the commands you entered most recently.  The number of commands

you can review is determined by the value of the history shell variable.

You can then use a variety of commands to review and repeat your saved

commands:



elaine24> set history = 10          Sets the number of commands for UNIX

                                    to save at n (10 here).

elaine24> history                   Displays the previous 10 commands,

                                    as set in the step above.

     11 emacs .alias

     12 who

     13 finger statman

     :

     19 cat todolist

     20 history



elaine24> !!                        Re-executes the immediately

history                             preceding command.

     12 who

     13 ...

      :

     20 history

     21 history



elaine24> !cat                      Repeats most recent command starting

                                    with string cat in the previous 10

cat todolist                        commands (as set above).

 *** don't forget lunch appointment tomorrow!



elaine24> !13                       Repeats command 13 if it is in the

                                    previous 10 commands.

finger statman

:





Saving Your Commands and the Shell's Responses:  Sometimes you may want

to save your commands and the shell's responses in a file.  That way,

you can see or print the information later.  You may want to record the

running of a specific program and inspect this session later, at your

leisure.  The script command saves the record of your interaction with

the shell in a file named typescript in the working directory.  You can

specify different file names if desired by typing script filename; type

man script at the shell prompt for more information.  To signal the end

of the recording, type the command exit.  At that point, you can look at

the typescript file by typing more typescript at the prompt.



elaine24> script                    Saves all commands and shell

                                    responses that follow.

Script started, script is typescript

csh> testprog

What is the result of 3+4? 7

Correct!

csh> exit     Ends the recording.

csh> Script done, file is typescript





elaine24> more typescript           Displays the commands and shell

                                    responses just saved.

Script started on Tue May 17 23:06:57 1988

csh> testprog

What is the result of 3+4? 7

Correct!

csh> exit

script done on Tue May 17 23:07:30 1988











Part V: Using EMACS

===================



About Part V:  EMACS is a text editing program available on the Leland

Systems;.  Part V is an introduction to EMACS, explaining how to use the

program.  For a more complete list of EMACS commands and functions,

refer to the EMACS Reference Card.



Most EMACS commands are executed with CONTROL (C-) and ESCAPE (ESC)

command sequences.  Refer to Command Sequences on page 3 for more

information.





Entering EMACS:  To enter the text editing program and create a new text

file, type the command emacs at the system prompt.  If you want to edit

a file that already exists, include its name (with the relative or

absolute pathname, if necessary) as the argument to the emacs command.



elaine24> emacs unix.doc



Upon startup, the editor copies the contents of the file specified in

the argument into an internal buffer, or work space.  If you didn't

specify a file, the editor creates a new, blank buffer.  During the

editing session, you make changes to this buffer and not to the contents

of the original file.  The original file remains unchanged until you

explicitly tell the editor to write over the old file with the contents

of the edit buffer.  Therefore, if you quit an editing session without

saving your changes, the file you worked on remains as it was before you

began the editing session.





Moving in the Text:  The cursor indicates your position within the text

of the buffer.  There are two ways to move the cursor.  On Macintosh

machines, and on some PCs and workstations, you can use the arrow keys

near the number pad.  If that doesn't work, or if that option isn't

available, use the following movement command sequences:



Backward     Forward



C-b          C-f       One character

ESC b        ESC f     One word

C-p          C-n       One line

C-v          ESC v     One screen

C-a          C-e       Beginning (or end) of line

ESC a        ESC e     One sentence

ESC <        ESC >     Beginning (or end) of buffer



To re-display text, with the line where the cursor is currently located

positioned in the center of the screen, type C-l.  To cancel a partially

typed or accidental command, type C-g.





Editing Text:  Any editing that you do will affect the character

immediately at or preceding the location of the cursor.  To insert text,

move the cursor one position beyond where you want the new text to go,

and type as normal.  Delete a character with the DELETE key.  Please

note that EMACS does not wrap text down to the next line.  Therefore,

you must press the RETURN key at the end of each physical line, before

you get to the right margin.





Saving Your Work:  You should save your work periodically during an edit

session to backup your changes.  Frequent saving minimizes loss of data

should the computer system crash.  To save any changes you have made in

the buffer, type C-x, then s.  This writes the contents of the buffer

over the original file.  To save the contents of the buffer to a new

file, type C-x, then C-w.  The editor then prompts you for a file name

for the saved buffer.



Note:  The normal save command sequence may cause some modem programs to

freeze.  If this is the case, type C-q to unfreeze the modem, then use

the C-x C-w command sequence and save the file with the same name.





Leaving EMACS:  To stop EMACS temporarily, type C-z.  Remember to save

your work first.  When you issue the command fg %job number at the

system prompt, the editor resumes where you left off.  For more

information, see Controlling Jobs on page 19.



To end an EMACS editing session, type C-x, then C-c.  Remember to save

your changes before exiting.  If you have modified the text in a buffer

and attempt to exit without saving your changes, the editor asks you if

want to save the changes.



For More Information:  Consult the document already mentioned, EMACS

Reference Card.  There is also an online tutorial for EMACS, which

provides a complete interactive introduction.  Type teachemacs at the

system prompt to start the tutorial.  For more detailed information on

the EMACS editor, you may want to attend an introductory class on EMACS.

These classes are offered at the beginning of Autumn, Winter and Spring

Quarters; class schedules are available for the first few weeks of each

quarter in the document racks on the second floor of Sweet Hall.  If you

have further questions about EMACS, contact a consultant at 725-2101,

consult@leland.









Part VI: Printing

=================



About Part VI:  You can print files or other text (e.g., output of

commands) at any of the printers in Sweet Hall or in the Meyer and

Tresidder Computer Clusters.  (In some clusters, you will have to set up

a printing account to have printing capabilities.)  Each printer has a

print queue, which contains the print jobs that are waiting to be

printed, lined up in the order in which they arrive at the printer.





Print Commands:  As shown in the following examples, the print commands

lpr, lpq and lprm are used to send a print job to a particular printer,

display the print queue and remove a request from a print queue.  A

useful argument for these commands is the -Pname, where name is the

printer you wish to use.  A useful option is -h, which suppresses the

header page to your print job, printing only the specified file and

saving one piece of paper.  Each UNIX system has a default printer; all

print jobs initiated from that system will print at the default printer,

unless you specify otherwise in the argument.



elaine24> lpr -h SOC22              Prints the file SOC22 on the default

                                    printer without the header page.



elaine24> lpr -Psweet0 SOC22        Prints the file SOC22 on the printer

                                    named sweet0.



elaine24> ls | lpr -h -Psweet0      Prints the output of the command ls

                                    on the printer sweet0.





elaine24> lpq -Psweet0              Displays print queue of the sweet0

                                    printer.

lp is ready and printing via dev

Rank   Owner      Job  Files             Total Size

1st    ksteele    105  SOC22             55706 bytes

2nd    ksteele    106  (standard input)     70 bytes



elaine24> lprm 106                  Removes job 106 from the default

                                    print queue.

                                    This only works if the job hasn't

                                    already been processed by the

                                    computer managing the queue.



If you are working on a UNIX workstation on the second floor of Sweet

Hall, you can use the printers sweet0, sweet1, sweet2 (the default

printer), sweet3, sweet4 and sweet5.  Sweet0 is a high-speed line

printer.  The rest are laser printers and are capable of handling files

in PostScript format.



For more information on the print commands and their options, consult

the online UNIX manual by typing man command.





Formatting a Print Command:  The enscript command allows you to format a

print job as you send it to the printer.  When you use enscript, your

files are printed with headers, and two pages of material are compressed

to fit on one page, saving paper.  Type man enscript at the system

prompt to consult the online UNIX manual for arguments that you can use

to format the output for a particular printer.



elaine24> enscript unix.doc -2r -G -h     Prints unix.doc with 2 columns

                                          (-2) and rotates the page (r)

                                          so that the columns are wider.

                                          -G adds a header to the top of

                                          each page, and -h suppresses

                                          the header page.



Note:  The enscript command does not work for printing PostScript files.

Type man postscript for information on printing PostScript files.



Changing the Default Printer  There are times when you may want to

change the default printer to another printer.  For example, the normal

default printer may be down, or perhaps an application you're using only

works with a specific printer.  To change the default printer, reset the

environment variables PRINTER to the name of the printer that you want

to use.  This changes the default printer until you log out.  For more

information, see Environment Variables on page 17.



elaine24> setenv PRINTER sweet2     Designates the printer sweet2 as the

                                    default printer











Part VII: Staying Informed about System Activity

================================================



About Part VII:  You can obtain information about a UNIX system's

status, changes made to the system, and a particular computer's recent

activity.  You can find out which other users are currently logged in,

and what a particular user is doing.





System Messages:  When you first log on to the Leland Systemss;, there

may be either a new system messages or information regarding an old one.

These messages are sent by the system administrators to inform users

about changes in the systems or in their accounts, and may instruct

users to change their passwords and/or a file in their home directories.





Finding Out About a Particular Computer:  The uptime command displays

information regarding the status of the computer you are working on:

the time, how long the machine has been up and

running, the number of users currently logged on, and the load average.

As more users log on to the system and do work, the load average

increases.  This gives you a rough idea of how busy the system is.



elaine24> uptime

12:10pm   up 1 day,   16:35,   2 users,   load average: 1.34, 1.28, 1.66



The who command displays who is currently logged in to the computer you

are on.  From left to right, the first entry is the user's login name,

followed by that person's terminal (tty) and the date, time, and

location of the login.



elaine24> who

tsoi       ttyp0     May 17     19:11     (109.83.1.130)

ksteele    ttyp1     May 17     19:03     (ksteele-macII)

jester     ttyp3     May 17     15:32     (jewel)



The command who am i displays that line of information only for the user

who is logged on to that terminal.  This is useful in finding who is

logged on to an unattended computer or workstation.  The w command is

similar to who; it lists all the users on the system and what they are

doing.





Finding Out About a Particular User:  To find out more information about

particular users, use the finger command.  When you use finger with no

arguments, you get abbreviated information (full name, tty, idle time,

login time, office) for each user on the computer you are using.  When

you use the command finger with a username and a host as the argument,

information on that user, including her .project and .plan files

display.



elaine24> finger ksteele@cardinal

Login name: ksteele                     In real life: Kate Steele

Directory: /s16/k/ksteele               Shell: /bin/tcsh

On since Jan 13 11:46:57 on ttyp3 from ksteele-macII

New mail received Wed Jan 13 13:08:06 1993;

     unread since Wed Jan 13 11:11:03 1993

Project: Finishing the UNIX documentation.

Plan: I'd like to teach the world to sing...



Please note that, due to system backups, the information about when a

user last logged in and/or read mail may be inaccurate.



Use a text editor to add messages or information to the .project and

.plan files in your home directory.  See Managing Files on page 8 for

more information on dot files.  These files should only contain

information that you would like other users to know about you.  Also, be

sure that you give permission for others to read your .project and .plan

files.  If you don't, people who finger your username won't be able to

see the information you include in those files.



To get more information on an individual user, or to find out who a user

is, use the whois command.  When you type whois user@host, you get a

user's actual name, e-mail username, Stanford affiliation, phone, fax

and office numbers, and other information.







Appendix A: UNIX Command Summary

================================



Appendix A lists the UNIX commands that appear throughout this document.

The first column lists the topic, the second lists the command, the

third contains a short definition for each command, and the last column

lists the page number on which the command first appears.  All

information in italics is variable input and should be replaced with

specific information, such as a file or directory name.



This information is meant primarily as a reference supplement for this

document.  There is a reference card, also called UNIX Command Summary,

that contains most of this information and can be used separately.  As

stated earlier in this document, there is also an online UNIX reference

manual.  See Getting Help below.



Beginning and Ending Work Sessions

----------------------------------



     login               Begins login process on the computer you want

                         to use.

     set term=term type  Tells UNIX system what kind of terminal you're

                         using.

     password            Allows you to change your password.

     logout              Logs you off the computer you've been using.



Getting Help

------------



     help                Accesses the online help files for various UNIX

                         commands.

     help docs           Accesses online documents about the Leland

                         Systems.

     man man             Displays information about the online UNIX

                         manual.

     man command         Consults online UNIX manual section about

                         command.

     man -k keyword      Lists all commands associated with keyword.

     learn               Starts UNIX tutorial program.



Managing Directories

--------------------



     pwd                 Prints your working directory.

     mkdir dir           Creates a new subdirectory called dir.

     cd                  Changes to your home directory.

     cd ..               Changes to directory one level above.

     cd dir              Changes to dir (use either the absolute or

                         relative pathname).

     rmdir dir           Removes subdirectory dir (must be empty).

     ls                  Lists contents of working directory.



Managing Files

--------------



     more file           Displays contents of file, screen by screen.

     head file           Displays the first 10 lines of file.

     tail file           Displays the last 10 lines of file.

     mv file1 file2      Moves or renames file1.

     cp file1 file2      Makes a copy of file1, and names it file2.

     rm file1            Permanently removes file1.

     cat file1 file2 > file3     Concatenates file1 and file2 into new

                                 file3.



Transferring Files

------------------



     ftp host            Starts file transfer program between your

                         machine and host.

     get file            Receives a copy of file from the remote

                         computer.

     send file           Sends a copy of file to the remote computer.

     quit                Ends file transfer program.



Security Changes

----------------



     ls -l               Lists contents of working directory with

                         security information.

     chmod useracc name      Changes type of access (acc) of user group

                              for a particular file or directory (name).

     fs listacl name     AFS only: shows access rights for a file or

                         directory (name).

     fs setacl name user acc  AFS only: changes type of access (acc) of

                              user for a particular file or directory

                              (name).



Re-directing I/O

----------------



     <, >                Redirects input and output in command lines.

     command >> file     Appends output of command to the contents of

                         file.

     command1 | command2      Uses output of command1 as input of

                              command2.





Shell-related

-------------



     exit                Quits from current shell.

     source .cshrc       Runs commands in .cshrc file.

     source .login       Runs commands in .login file.

     set variable=setting     Sets the specified shell variable to

                              setting for this work session.  Some

                              common shell variables are path, prompt,

                              history and term.

     echo $variable      Displays the setting for variable.

     unset $variable     Removes the setting for variable.

     setenv VARIABLE     Sets environmental VARIABLE to setting for this

          setting        work session.

     printenv            Displays environmental variables and their

                         settings.

     unsetenv VARIABLE   Removes setting for VARIABLE.

     alias name command       Allows you to refer to the command line

                              command with the shorter term  name.

     alias               Displays the aliases you have set up.

     unalias name        Removes name from active aliases.



Controlling Jobs

----------------



     jobs                Shows status of currently running jobs by job

                         number.

     ps                  Shows status of currently running jobs by

                         process identifier.

     command &           Specifies that the job started by command run

                         in the background.

     stop $job#          Temporarily stops specified job.

     bg %job#            Resumes specified job in background.

     fg %job#            Brings specified job from background to

                         foreground.

     kill $job#          Permanently stops specified job.

     history             Displays last ten commands used.

     !command#           Re-executes specified command.

     script              Saves the following interaction with the shell

                         to a file so it can be viewed again later.



EMACS

-----



     emacs               Begins a new text document.

     emacs file          Places the contents of file in a buffer for

                         text editing.

     teachemacs          Starts EMACS tutorial.

     C-x s               Saves changes to the file.

     C-x C-w             Saves changes to a new file.

     C-z                 Stops EMACS temporarily.

     C-x C-c             Quits EMACS.





Printing

--------



     lpr file            Prints file at default printer

     lpr -h file         Prints file at default printer, suppressing the

                         header page.

     lpr -Pprinter file  Prints file at printer.

     lpq                 Displays print queue of default printer

     lprm job#           Removes specified print job from print queue.

     enscript -2r -G -h file  Adds heading information to each page of

                              file and prints two columns per page;

                              suppresses header page.



System Activity

---------------



     uptime              Displays status of computer you are working on.

     who                 Displays information on other users logged on

                         to the same computer.

     who am i            Displays information on user logged in at

                         specific computer or workstation.

     finger user         Displays information about user.

     whois user@host     Displays information about user.



Miscellaneous

-------------

(These commands are not explained in this document.)



     sort file           Sort each line of file alpha-numerically.

     spell file          Conducts a spell check on contents of file.

     date                Displays the date and time.

     fs listquota        AFS only: displays disk quota and usage.

     quota -v            Non-AFS only: displays disk quota and usage.

     telnet host         Allows you to connect to remote computer host.

     grep "string" file  Displays all lines in file that contain the

                         words string (in quotation marks).







Appendix B: Using Compilers-A Quick Guide

=========================================



About Appendix B:  This appendix provides a brief introduction to

compiling, covering the C, Pascal and FORTRAN languages.  Other

languages are compiled similarly.  This appendix assumes that you know

how to use the language you are working with.  It  also assumes that you

know how to use a text editor such as EMACS.  To see a list of compilers

available on the Leland Systems;, type the command man -k compiler.



A compiler produces a machine language program from the source program

that you create.  Using UNIX, it translates the source program into the

basic language of the computer; programs written in machine language

require no further interpretation by the computer.





Compiling Procedures:  This section uses the C language in its examples.

(The C programming language is closely related to UNIX; most of the UNIX

operating system and its commands are written in C.)  These procedures

are basically the same for Pascal and FORTRAN-only the extensions and

the names of the compilers change, as described in the following

sections.



1. Use a text editor to create one or more files containing the source

   program.  You must write the source program in a development

   language.  Each file containing the source program should end with an

   extension, specifying which language is used (e.g., .c for C).



2. After creating the source program, invoke the compiler for that

   language.  The compiling command takes as its argument the name of

   the file(s) containing the source program.  (For more information on

   the C compiler, use the command man cc.)



elaine24> cc main.c      Compiles from the file main.c.



If the system prompt returns, the compiler has successfully converted

the source program into a machine executable program, i.e., a program

that you can run.  Unless you specify otherwise, the name of this

program is a.out.  To run this program, simply type its file name:



elaine24> a.out                    Runs the new program.





elaine24> cc -o myprog main.c      Allows you to specify the name of the

                                   executable file or program (instead

                                   of a.out, it will be myprog).



If the program doesn't run as expected, i.e., the program 'bombs' or the

results aren't what you expect, use a de-bugging program such as dbx to

diagnose the problem.  (For more information on dbx, type man dbx.)

Once you've isolated the problem, use a text editor to correct the

error.



If the compiler cannot compile the file(s), error messages display on

the screen.  If you are compiling a single file, the message tells you

which lines contain errors.  If you are compiling multiple files, the

message tells you which lines within which files contain errors.  Use a

text editor to correct the errors.



To check individual files before compiling multiple files, follow these

steps:



elaine24> cc -c main.c   Compiles the file main.c, creating an

                         intermediate file main.o, which can be used

                         later to create the executable file or program.

                         This is useful when you have edited a file and

                         want to check to make sure it will compile

                         successfully before you compile it with the

                         other files comprising your program.



elaine24> cc -o myprog main.o display.c     Creates executable file or

                                            program from files main.o

                                            and display.c.



Compiling with Pascal:  The name of each file containing the source

program should end with the extension .p, such as main.p.  The Pascal

compiler is called pc.  Compiling procedures are the same as those for

C.  (For more information on the Pascal compiler, use the command man

pc.)





Compiling with FORTRAN:  The name of each file containing the source

program should end with the extension .f, such as main.f.  The FORTRAN

compiler is f77.  Compiling procedures are the same as those for C.

(For more information on the FORTRAN compiler, use the command man f77.)





Using Libraries While Compiling:  You can include a library in your

program, in addition to the standard input/output library, in order to

use their pre-existing subroutines.  It is very important that you place

the -l option after the name of your source file(s) on the command line.

Otherwise, the external library routines may not be correctly linked to

your program.  The following example uses a C library:



elaine24> cc main.c -lm  The l option indicates you are calling up a

                         library.  The m here stands for the math

                         library, which includes functions for

                         calculating sine, cosine, and other useful

                         mathematical functions.



Some of the Leland Systems have FORTRAN libraries like IMSL and NAG

installed.  To use subroutines from those libraries in your own FORTRAN

programs, use these commands:



elaine24> f77 main.f -limsl    Uses the IMSL library.



elaine24> f77 main.f -lnag     Uses the NAG library.


Last modified Thursday, 19-Jan-2006 11:26:32 AM

Stanford University Home Page