Introduction

Why C and UNIX?

UNIX Basics

(pp 10 - 13)

UNIX is a multiuser operating system - it permits multiple users on the same computer at the same time.

Consequences:

user id
a public identifier that uniquely identifies a user of a UNIX system
password
a secret string of characters used to prove that a user is who he/she claims to be

Thus, each user needs both a user id and password to gain access (login) to a UNIX system. Both a public and private identification mechanism are needed.

Your password should:

We'll be using a group (cluster) of UNIX workstations at U.P.
Steps for logging in:

  1. get an account (from me)
  2. go to W208, W304 or W305 and pick a PC
  3. turn on the PC and monitor if necessary (it will take several minutes to boot)
  4. start Windows if necessary by entering
    w31
    
    at the C: prompt
  5. using the left mouse button, double click on the Internet Apps icon
  6. double click on the telnet icon
  7. enter the name of the computer you want to use. In our case:
    farman.cac.psu.edu
    
  8. enter your user id at the login prompt
    login:
    
  9. enter your password at the password prompt
    password:
    

You're in!

The first thing to do is to change your password to one that satisfies our criteria.

  1. Enter the command:
    passwd
    
    note the missing or
  2. You will be prompted to enter your old password. Do so.
  3. You will be prompted to enter your new password. Do so.
  4. You will be prompted to confirm your new password. Enter it again.
Next time you login, use your new password. You don't need to change your password every time you log in, but it is a good idea to change it occasionally.

It is vital to logout (end your user session) when you are finished. Otherwise, anyone can sit down and access your files, etc. Use the

logout
or
exit
command to logout. If logout doesn't work, exit will. Close the telnet window by double clicking in the small box in the upper left hand corner of the window.

Return to Table of Contents

Creating and Editing Files with vi

(pp. 32 - 35)

vi is a text editor that is a standard part of UNIX. To allow full screen editing, vi needs to know what type of terminal you are using. This is done by setting the environment variable term. Environment variables are used to tell UNIX what customizations you would like in your account. We'll set term to vt100, which works well with PCs and is adequate for us. Either of the following commands will work:

set term = vt100
or
setenv TERM vt100
Now vi will work correctly. To create a new file with name filename or edit file filename, enter:

vi filename

vi has 3 modes:

input mode
used for entering text into a file
command mode
used for entering commands (not echoed on screen)
ex mode
another mode for entering another set of commands (shown at the bottom of the screen)

Initially, vi is in command mode. The file vi.txt summarizes the use of vi.

To avoid having to set term every time you log in, put the appropriate setting in your .cshrc file. This file is executed every time you log in, and so is the best place to set environment variables.

Return to Table of Contents

Basic UNIX Commands

(pp. 13 - 18)

Many UNIX commands take parameters, which specify inputs for the command. e.g. vi takes a file name.

Many UNIX commands also use flags, which modify the meaning of the command slightly. Flags are usually one letter codes preceded by a dash. e.g. -a

Multiple flags can be combined - the following have the same meaning:

ls -a -l
ls -al

If a command takes both parameters and flags, the flags usually precede the parameters. e.g.

ls -l vi.txt

Some of the more important UNIX commands are summarized in the file unix.txt.

Hidden files have file names that start with a period. These files are not shown by ls unless the -a flag is used. Hidden files are usually used to hide system files that users rarely need to see or modify. e.g. the .cshrc file.

A text file containing UNIX commands (such as the .cshrc file) can be executed, causing all the UNIX commands it contains to be executed. This is done using the source command. E.g.:

source .cshrc
lets you see the effects of any modification of your .cshrc file.

Do not try the lpr command as described in the text. The machines we are using are located at U.P., so using this command will cause something to print there. To print file filename, use:

lpr -Pcap1 filename

The -P flag lets you specify the printer to send the file to by name. Your print out will go to the laser printer behind the desk in W305 Olmsted. If the student operator on duty doesn't have your print out placed on the counter at the front of the room, ask him or her for it.

You can also use ftp from a PC to download your file to that PC for printing.

Return to Table of Contents

The UNIX File System

(pp 63 - 65)

UNIX uses a directory structure similar to that of the DOS or MacIntosh operating system.

Each user has a directory, called their home directory. When you log in, you are automatically placed in your home directory. Usually, your home directory has the same name as your user id.

When one directory contains another:

The working directory is the directory you are currently in.

Files and directories in the working directory can be referred to just by name (as we've been doing). Files and directories in other directories can be referred to in 2 different ways:

The tilde (~) can be used as a shorthand for your home directory. For me,

vi ~/pub/vi.txt
is equivalent to the absolute path above.

Relative and absolute paths can be used when referring to files or directories for any UNIX command. E.g.:

cd ../pub
cd ~/pub
mv foo ~/pub

To avoid having to use paths when referring to UNIX commands and any locally installed software, the environment variable path is used. This specifies all paths to be searched for executable commands. E.g.:

setenv PATH /usr/bin:/usr/ucb:/usr/local/bin
Your path has already been set in your default .cshrc file.

Similarly, the environment variable manpath can be used to specify all directories where manual pages (used by the man command) are located. Unless manual pages are placed in nonstandard locations, this variable need not be set.

Return to Table of Contents

Protection Modes

(pp. 65 - 67)

In UNIX, access to files and directories is controlled through three protection modes.

What UNIX protection modes mean for files and directories.
modefiledirectory
read permission ability to see contents and copy the file ability to list files via ls
write permission ability to delete file or modify contents ability to create, modify and delete files in the directory
execute permission ability to run the file (e.g. a.out) ability to cd into the directory or access files in the directory

If you own a file or directory, you can set the protection mode for three different groups of users:

user group definition of that group
user just you
group those in your group
use the id command to see what groups you are in
others everyone else

The protection modes in force for a file or directory are displayed by the ls -l command.

Example - my file vi.txt and my pub directory:

-rw-r--r--  1 taw2         3484 Aug 27 14:36 vi.txt
drwxr-xr-x  3 taw2         1536 Apr 29 17:30 pub
The format of these entries is: protection modes, number of links, owner, size in bytes, date (and time) of last modification and file or directory name. The format of the protection modes part is:

The owner of a file or directory can change permissions of that file or directory using the chmod command. This command takes two parameters: protection mode changes and a file or directory name (or path).

Example:

chmod o+rwx unix.txt

In the protection mode changes parameter:

To keep others from copying or deleting your homework in file assign1.c:

chmod o-rwx assign1.c
chmod g-rwx assign1.c

If you put all your assignments in a directory called assignments:

chmod o-x assignments
chmod g-x assignments
will prevent anyone from reading or modifying any contents of that directory (including subdirectories) except system administrators.

Return to Table of Contents