|
|
 |
 |
 |
 |
bbs |
search |
rss |
faq |
about |
register
|
 |
 |
digg |
del.icio.us |
sphere |
google
|
 |
|
Beginners Guide to understanding Unix
NOTICE: TO ALL CONCERNED Certain text files and messages contained on this site deal with activities and devices which would be in violation of various Federal, State, and local laws if actually carried out or constructed. The webmasters of this site do not advocate the breaking of any law. Our text files and message bases are for informational purposes only. We recommend that you contact your local law enforcement officials before undertaking any project based upon any information obtained from this or any other web site. We do not guarantee that any of the information contained on this system is correct, workable, or factual. We are not responsible for, nor do we assume any liability for, damages resulting from the use of any information on this site.
UNIX for Beginning Users
Developed by:
User Liaison Section, D-7131
Denver Office
[Name and Phone number deleted at authors
Request]
Revision Date: September 16, 1991
I. INTRODUCTION
A. Audience
This course is for individuals who will be using the UNIX
operating system on a Reclamation computer platform. It is
assumed that the student has a general understanding of data
processing concepts.
B. Course Objectives
Upon successful completion of this course the student will be
able to:
1. Demonstrate a knowledge of basic UNIX ideas.
2. Recognize the different types of files and the file
structure.
3. Log in and out of UNIX using an interactive terminal.
4. Change the password and be aware of other
responsibilities of owning an account.
5. Demonstrate a knowledge of where to get help.
6. Use the appropriate UNIX commands to display/print
files, copy/move files, change file access permissions,
create/delete directories, and change the current
working directory.
7. Transfer a file to another computer platform using File
Transfer Protocol (FTP). Use FTP commands to do the
following: initialize FTP, establish connection, local
computer commands, remote computer commands, close
connection, exit FTP, help command, and special
functions.
8. Use an editor to create files, input text,
insert/replace text, copy/move text, and exit/save
changes.
9. Use the mail utility to send/receive/delete messages
10. Use basic Annex commands to reestablish connection to a
disconnected process.
C. Course Handout Conventions
There are several conventions used in this handout for
consistency and easier interpretation:
1. Samples of actual terminal sessions are single-lined
boxed.
2. User entries are shown in bold print and are
underlined.
QUIT
3. All keyboard functions in the text will be bold.
(Ret) Backspace
Tab Ctrl-F6
Print (Shift-F7) Go to DOS (1)
NOTE: (Ret) indicates the Return or Enter key
located above the right Shift key.
4. Examples of user entries not showing the computer's
response are in dotted-lined boxes.
5. Command formats are double-lined boxed.
6. Three dots either in vertical or horizontal alignment
mean continuation or that data is missing from the
diagram.
?????????????????????????????????????????????????????????????????
? ?
? ?
? Multimax, Nanobus, and UMAX are trademarks of ?
? Encore Computer Corporation ?
? ?
? ?
? Annex is a trademark of XYLOGICS, Inc ?
? ?
? ?
? UNIX and Teletype are registered trademarks of ?
? AT&T Bell Laboratories ?
? ?
? ?
? Ethernet is a trademark of Xerox Corporation ?
? ?
? ?
? ?
?????????????????????????????????????????????????????????????????
1. BASIC UNIX IDEAS
The UNIX operating system is a set of programs that act as a link
between the computer and the user. The programs that allocate
the system resources and coordinate all the details of the
computer's internals is called the operating system or kernel.
Users communicate with the kernel through a program known as the
shell. The shell is a command line interpreter; it translates
commands entered by the user and converts them into a language
that is understood by the kernel.
Here is a basic block diagram of a UNIX system.
Spread Sheet Compilers
Calculators ?
? ?
V V
?????????????????????????????????
? The Shell ? Mail and
? ???????????????????????? ?<- Message
Inventory ? ? UNIX system kernel ? ? Facilities
Control --->? ? ???????????????? ? ?
Systems ? ? ? ? ? ?<- Interpreters
? ? ? Hardware ? ? ?
Formatters ->? ? ? ? ? ?<- DBMS
? ? ? ? ? ?
Calendar ? ? ???????????????? ? ? Word
Systems ---->? ? ? ?<- Processors
? ???????????????????????? ?
Editors ---->? ?<- FTP
?????????????????????????????????
The designers of UNIX used the following Maxims while writing the
new operating system.
1. Make each program do one thing well. These simple
programs would be called "tools."
2. Expect the output of every program to be the input to
another program.
3. Don't stop building new "tools" to do a job. The
library of tools should keep increasing.
1.1 The UNIX System
The main concept that unites all versions of UNIX is the
following four basics:
Kernel
The kernel is the heart of the operating system. It schedules
tasks and manages data storage. The user rarely interfaces with
the kernel directly. This is the memory resident portion of the
operating system.
Shell
The shell is the utility that processes your requests. When you
type in a command at your terminal, the shell interprets the
command and calls the program that you want. The shell will
support multiple users, multiple tasks, and multiple interfaces
to itself. The shell uses standard syntax for all commands.
There are two popular shells currently available, the BourneShell
(standard System V UNIX) and the CShell (BSD UNIX). Because
separate users can use different shells at the same time, the
system can appear different to different users. There is another
shell known as the KornShell (named after its designer), which is
popular with programmers. This ability to provide a customized
user interface is one of the most powerful features of UNIX.
Commands and Utilities
Separate utilities can be easily combined to customize function
and output. They are flexible, adaptable, portable, and modular.
They use pipes and filters. There are over 200 standard commands
plus numerous others provided through 3rd party software.
Files and Directories
The directory system supports a multilevel hierarchy. Files and
directories have access protection. Files and directories are
accessed through pathnames. Files support multiple name links.
Removable filesystems are also supported.
1.2 File Structure
All data in UNIX is organized into files. All files are
organized into directories. These directories are organized into
a tree-like structure called the filesystem. The following
diagram describes the top level organization of the UNIX
filesystem:
/
(root)
?
???????????????????????????????????????????????
? ? ? ? ? ? ?
bin dev etc lib tmp usr users
These directories, in turn, are also organized hierarchically.
For example:
/
?
????????????????????????????????????????????
? ? ?
dev etc usr
? ? ?
???????? ???????? ?????????????????????????
? ? ? ? ? ? ?
dsk rmt init.d rc0.d mail adm spool
?
?????????
? ?
acct sa
In this example, dev, etc, usr, and adm are directories.
Directories contain other files or directories. Plain files
contain text or binary data and contain no information about
other files or directories.
Users can make use of this same structure to organize their
files.
For example:
/
?
????????????????????????????????
? ? ?
bin users dev
?
???????????????????????????????
? ?
bsmith sjones
? ?
???????????? ???????????????????????????
? ? ? ? ?
memos progs physics chem history
? ? ? ? ?
??????? ???????? ???????? ??????? ?????
? ? ? ? ? ? ? ? ? ?
mfg eng c f77 mods calcs forms notes loc anc
Every file has a name. A filename is composed of one to fourteen
characters. Although you can use almost any character in a
filename, you will avoid confusion if you choose characters from
the following list.
1. upper case letters [A-Z]
2. lower case letters [a-z]
3. numbers [0-9]
4. underscore [_]
5. period [.]
6. comma [,]
The only exception is the root directory, which always uses the
symbol /. No other directory or file can use this symbol.
Like children of one parent, no two files in the same directory
can have the same name. Files in different directories, like
children of different parents, can have the same name.
The filenames you choose should mean something. Too often, a
directory is filled with important files with names like foobar,
wombat, and junk. A meaningless name won't help you recall the
contents of a file. Use filenames that are descriptive of the
contents.
1.3 UNIX System Files
In order for you to have a basic understanding of the contents of
some of the system directories, here is a partial list of those
directories and what files they contain:
/bin This is where the executable files are located.
They are available to all user.
/dev These are device drivers.
/etc Supervisor directory commands, configuration
files, disk configuration files, reboot files,
valid user lists, groups, ethernet, hosts, where
to send critical messages.
/lib compiler libraries
/tmp scratch processes, editors, compilers, and
databases
/bsd Berkeley commands
/mnt empty, used for disks
/stand boot information
/lost+found orphans go here (look here after system crash)
/unix* executable, bootable kernel
This is not an exhaustive list of directories that contain system
information but it is intended to remove some of the mystery
behind these directories and the types of files they contain.
1.4 Command Line Syntax
Users enter commands at the shell prompt. The default
BourneShell prompt is the dollar sign ($). In general, the shell
expects to see the following syntax:
?????????????????????????????????????????????????????????????????
? Command Format: command options arguments ?
?????????????????????????????????????????????????????????????????
Command - This is the UNIX command. Sometimes the command
is representative of the function. For example,
the command to list the contents of a directory is
ls. The first and third letters of the word
"list" are used. Unfortunately, this is not
always the case.
Options - These are also known as flags. The common form
is:
-A
where A is the abbreviation of the optional
function of the command. For example, the command
ls lists the contents of a directory, while the
command ls -l provides a long listing and ls -C
provides output in columns. Several options can
be combined following one '-'; for example -CF, or
they can be entered separately as -C -F.
Arguments - These can be file names, user names, or qualifiers
to the command or one of its options.
Example:
.................................................................
. $ls -CF sjones .
.................................................................
The UNIX command is ls list contents of directory the dash (-)
indicates the options.
C = Multiple-column output with entries sorted down the
columns
F = Put a slash (/) after each filename if that file is a
directory and put an asterisk (*) after each filename
that is executable.
sjones = name of the directory to list (it can be a
relative or absolute pathname)
Example:
.................................................................
. $diff memo1 memo2 .
.................................................................
diff - differential file comparator command
memo1 - filename argument
memo2 - filename argument
This command will tell what lines must be changed in two files to
bring them into agreement.
Here is another example that doesn't fit the general syntax for
UNIX commands.
Example:
.................................................................
. $find . -atime +7 -print .
.................................................................
find - find files
. - the current working directory
-atime - True if the file has been accessed in n days (n is
the +7)
-print - always true; causes the current path name to be
printed
So, this command will give a listing of all files in your current
working directory that have been accessed in the past seven days.
Some commands have several options and/or arguments; while
others, like passwd and mail, are interactive and will prompt the
user for additional input.
1.5 Correcting Mistakes
Because the shell and most other utilities do not interpret the
command line (or other text) until you press the (Ret) key, you
can correct typing mistakes before you press (Ret). There are
two ways to correct typing mistakes. You can erase one character
at a time, or you can back up to the beginning of the command
line in one step. After you press (Ret), it is too late to make
a correction.
1.5.1 Erasing Characters
When entering characters from the keyboard, you can backspace up
to and over a mistake by pressing the erase key (#) one time for
each character you wish to delete. The # will appear on the
screen, and the character preceding it will be discounted.
Example:
.................................................................
. $ls phajne#y .
.................................................................
In this example, the e will be ignored and ls phajny is sent to
the Multimax. Multiple typos can be erased; simply press one #
for each character to be erased. The erase key will back up as
many characters as you wish, but it will not back up past the
beginning of the line.
1.5.2 Deleting an Entire Line
You can delete an entire line you are entering any time before
you press (Ret) by pressing the kill key (@). When you press the
@ (kill key), the cursor moves down to the next line and all the
way to the left. The shell doesn't give you another prompt, but
it is as though the cursor is following a prompt. The operating
system does not remove the line with the mistake but instead
ignores it. Now enter the command (or text) again from the
start.
1.5.3 Aborting Program Execution
Sometimes you may want to terminate a running program. UNIX
might be performing a listing that is too long to display on your
screen or for some other reason you want to terminate execution.
To terminate program execution press the Delete key. The
operating system sends a terminal interrupt signal to the shell.
When the shell receives this signal, it displays a prompt and
waits for another command.
1.5.4 Controlling Output to the Screen
There are several ways to control the flow of characters to the
screen as a result of executing a command. Such as:
Ctrl-S - This keyboard function command will suspend
the flow of characters to the screen as the
result of executing a command. The screen
will not continue until the keyboard function
to resume output is given.
Ctrl-Q - This keyboard function command will resume
the output to the screen.
Hold Screen - If your terminal has this key (i.e. VT200),
you can press it once to stop output to the
screen. To resume output to the screen,
press the key again.
Denver BOR MULTIMAX
Each BOR Multimax 310 has four 15 Megahertz National
Semiconductor 32-bit processors with 64 kilobytes of cache memory
rated at 2 million instructions per second (MIPS) for a total of
8 MIPS. The main memory consists of 32 megabytes (million bytes).
There can be a maximum of 14 disk drives. Each drive has a
capacity of 600 megabytes for a total capacity of 8.4 gigabytes
(a gigabyte is one thousand million bytes)
Connection to the Multimax is accomplished through one of several
methods. Access is made through TCP/IP based Annex terminal
servers. The two Annex II servers have 32 ports each and the
Annex I has 16 ports. The Annex II servers will allow up to 64
users access to the two Multimax computers. The Annex I is used
for access to the on-line printers. CDCnet and TELNET are other
ways to gain access to the Multimaxes.
Printouts are handled on a 600-line-per-minute line printer and a
10-page-per-minute laser printer. Each Multimax has a hardcopy
terminal and a CRT to serve as an operator console. There are two
tape drives capable of 1600 or 6250 bits per inch (bpi) on each
system. There is also a cassette tape drive.
Software available are FORTRAN, COBOL, C, and UNISOL (an
accounting package). The database management system is INGRES by
Relational Technology, Inc. PROCOMM+ will be the communication
interface with IBM PC's and compatibles. The operating system for
the Multimax is UMAX V. UMAX V is the name for the Encore
implementation of UNIX System V.
1.6 Logging on the Annex
This sample session shows how the login process is displayed on
the terminal screen and is uniform for all users. To bring the
standard menu onto the screen, press the Space Bar. If you are
using a PC, first start PROCOMM+. Then when you are in the
Terminal-Mode Screen, press the Space Bar; and the MICOM menu
will appear.
NOTE: Login procedures from the regions are included in the
back of this manual
Sample Session:
?????????????????????????????????????????????????????????????????
? WELCOME TO THE B.O.R. NETWORK P/S:B ?
? SYSTEMS PRESENTLY AVAILABLE ARE: ?
? ?
? **SYSTEM** **NAME** ?
? ?
? VAX 8300'S VAX ?
? CYBER/CDCNET F.E. CDC ?
? ENCORE/UNIX MAX ?
? OUT DIAL OD ?
? ?
? TO SELECT A SYSTEM, ENTER THE SYSTEM ?
? NAME AND CARRIAGE RETURN AT NEXT ?
? PROMPT. ?
? ?
? CHANNEL 08/061. ENTER RESOURCE MAX ?
? ?
?????????????????????????????????????????????????????????????????
MAX is the resource name you must enter to be connected to the
Annex, which is the Multimax front end processor. Some MICOM
menus might not have the MAX selection; in this case, enter MAX
to select the Annex. This is the same as if the menu showed the
option.
After entering MAX you will see something similar to the
following:
Sample Session:
?????????????????????????????????????????????????????????????????
? CONNECTED TO 06/011 ?
?????????????????????????????????????????????????????????????????
This indicates that you are connected to the port selector. Wait
two seconds, press (Ret) twice, and the annex prompt will appear
after a warning message.
Sample Session:
??????????????????????????????????????????????????????????????????????????????
? ?
? Annex Command Line Interpreter * Copyright 1988 Xylogics, Inc. ?
? ?
? ***WARNING***Unauthorized access to U.S. Government computers ?
? is punishable by fine and/or imprisonment. ***WARNING*** ?
? annex: ?
??????????????????????????????????????????????????????????????????????????????
1.7 Logging on the Multimax
To establish a connection between the Annex and the Multimax
enter the following command at the Annex prompt:
?????????????????????????????????????????????????????????????????
? Command Format: rlogin <host> ?
? ?
? host - name of the Multimax ?
?????????????????????????????????????????????????????????????????
The Denver Multimaxes have been assigned the names domax0 and
domax1. The names stand for the Denver Office Multimax System 0
and 1. The domax0 is used for production of Bureau-wide
applications. The domax1 is used for training and application
development and it is the one to use for exercises associated
with this course.
To enter domax1 type:
Sample Session:
?????????????????????????????????????????????????????????????????
? annex:rlogin domax1 ?
?????????????????????????????????????????????????????????????????
or
?????????????????????????????????????????????????????????????????
? annex:r domax1 ?
?????????????????????????????????????????????????????????????????
NOTE: Abbreviations are allowed for the Annex commands, the
only requirement is to type in enough characters to
make it unique.
When the Annex has opened communications with the selected host,
the following prompt will appear:
Sample Session:
?????????????????????????????????????????????????????????????????
? login: ?
?????????????????????????????????????????????????????????????????
To connect with the host, enter your login name at the prompt.
Your login name is assigned to you by the system administrator
and typically will be your first initial and last name, all one
word with no spaces. Only 8 characters are allowed for the
username so extra letters will be truncated.
Sample Session:
?????????????????????????????????????????????????????????????????
? login:rharding ?
?????????????????????????????????????????????????????????????????
Once the login name has been accepted, the next prompt will be
for the password. The following prompt will appear on the
screen.
Sample Session:
?????????????????????????????????????????????????????????????????
? Password: ?
?????????????????????????????????????????????????????????????????
Enter your password. For security reasons, the host will not
display your password as you type it.
Sample Session:
?????????????????????????????????????????????????????????????????
? Password: secret ?
?????????????????????????????????????????????????????????????????
Once you have entered the correct password. The login procedure
will continue and the following will appear on the monitor
screen.
Sample Session:
??????????????????????????????????????????????????????????????????????????????????
? UNIX System V Release ax.2.2o ns32332 ?
? domax1 ?
? Copyright © 1984 AT&T ?
? All Rights Reserved ?
? ***WARNING***Unauthorized access to/use of this U.S. Government ?
? computer is punishable by fine and/or imprisonment. ***WARNING***?
? $ ?
??????????????????????????????????????????????????????????????????????????????????
At this point you are successfully signed on to the Multimax.
The dollar sign ($) is the default prompt for the BourneShell.
1.8 Logging Off the Multimax
At the shell prompt $, you can logout of the Multimax using one
of the following methods:
1. Enter the keyboard function command Ctrl-D.
2. Type the UNIX command exit.
Once you have entered the command to logout the following will
appear on the screen:
Sample Session:
?????????????????????????????????????????????????????????????????
? $exit ?
? CLI: Connection closed. ?
? annex: ?
?????????????????????????????????????????????????????????????????
Once you are back at the Annex prompt, you can establish another
connection or logout of the Annex.
1.9 Logging Off the Annex
When the Annex prompt (annex:) appears, you can enter the command
to logout of the Annex. The command to logout of the Annex is as
follows:
?????????????????????????????????????????????????????????????????
? Command Format: hangup ?
?????????????????????????????????????????????????????????????????
There is a 60 minute inactivity timeout programmed into the
Annex; however, it is a waste of resources if you don't enter
hangup. When you are finished with your session, be sure to enter
hangup at the annex: prompt.
If you don't type anything for 60 minutes, the Annex will log you
out of the system and display the following message:
Sample Session:
?????????????????????????????????????????????????????????????????
? *** Annex Port Reset Due to Inactivity Timeout *** ?
? ?
? Annex Command Line Interpreter ?
? DISCONNECTED ?
?????????????????????????????????????????????????????????????????
When the hangup command has been entered, the following will
appear on the screen:
Sample Session:
?????????????????????????????????????????????????????????????????
? annex: hangup ?
? ?
? Resetting line and disconnecting. ?
? ?
? ?
? Annex Command Line Interpreter * Copyright 1988 Xylogics ?
? annex: ?
? DISCONNECTED ?
?????????????????????????????????????????????????????????????????
1.10 Changing the Password
The following command will change the password.
?????????????????????????????????????????????????????????????????
? Command Format: passwd ?
?????????????????????????????????????????????????????????????????
You will be prompted to enter the existing password (this
question is skipped if you don't have a password). Next you will
be prompted to enter the new password. You will then be asked to
enter the new password again. This will verify that you have not
made a typographical error. If the two entries are the same, the
password will be changed. The new password must meet the
following criteria:
NOTE: Some of these items are configurable by the system
administrator and these reflect the settings for the Denver
Multimax only.
1. Each password must have at least six characters. Only
the first eight characters are significant.
2. Each password must contain at least two alphabetic
characters and at least one numeric or special
character. Alphabetic characters can be upper or lower
case.
3. Each password must differ from the login name and
any reverse or circular shift of that login name.
For comparison purposes, an upper case letter and
its corresponding lower case letter are
equivalent.
4. A new password must differ from the old by at
least three characters. For comparison purposes,
an upper case letter and its corresponding lower
case character are equivalent.
Passwords on the Multimax have a thirteen-week expiration period.
At the end of the thirteen weeks, you will be required to change
your password. Once you have changed the password, you cannot
change it again for two weeks. This prevents you from
immediately changing back to the old password and eliminates a
possible security violation. If you try to change the password
before two weeks have passed since the last change, a warning
message will be displayed.
Sample Session:
?????????????????????????????????????????????????????????????????
? $passwd ?
? Changing password for teacher ?
? Old password: secret ?
? Sorry: < 2 weeks since the last change ?
? $ ?
?????????????????????????????????????????????????????????????????
NOTE: This is about as friendly as UMAX will ever get.
Try to choose a password that is not easy for someone else to
guess. The increasing number of computer crimes involving thefts
all point to a need for protecting the system from unauthorized
access. Do not use words like your birthdate, telephone number,
spouse's name, child's name, etc. for passwords. Although you
may think passwords are an unnecessary nuisance, they are an
important way to strengthen the security of the computer system.
1.11 On-line Manual
The major source of on-line help is in the form of documentation
known as the on-line manual pages. The pages are divided into
eight sections. Section 1 contains entries for UMAX user
commands; the other sections describe administrative tools,
library functions, games, and internal system structure and
calls.
To gain access to the on-line manual pages enter the following
command:
?????????????????????????????????????????????????????????????????
? Command Format: man <command> ?
? ?
? command - the UNIX command you want information about ?
?????????????????????????????????????????????????????????????????
NOTE: The name 'man' stands for manual.
Example:
.................................................................
. $man ls .
.................................................................
This command will display the on-line manual pages for the ls
command.
The on-line manual pages entry begins with the command name and a
one line summary followed by a synopsis of the command line
syntax. Optional flags and arguments are enclosed by square
brackets []. A detailed description of the command and all of
its options and arguments follow the synopsis. The description
can include helpful examples. At the conclusion of the entry,
related files and commands are listed.
NOTE: Most on-line manual pages will fill more than one
screen. Be sure to control the output to your screen.
1.12 who and finger Commands
Once you have logged onto the Multimax, you can find out who is
logged on the system with the following commands:
?????????????????????????????????????????????????????????????????
? Command Format: who [options] ?
? ?
? options - see man pages for a complete list ?
? ?
?????????????????????????????????????????????????????????????????
The default output (no options) of the who command lists the
user's login name, terminal line, and the time that the user
logged in.
Sample Session:
?????????????????????????????????????????????????????????????????
? $who ?
? jwheeler ttyp0 Aug 15 10:26 ?
? mvlsdba rt02190 Aug 15 09:25 ?
? teacher rt020b0 Aug 15 11:07 ?
? eholderf rt021c0 Aug 15 11:03 ?
? dbowman rt01150 Aug 15 08:58 ?
? $ ?
?????????????????????????????????????????????????????????????????
Options will display other information about the users that are
currently logged onto the system. Some items available are the
amount of time that has elapsed since activity occurred on that
line, the process identifier (PID) of the login process,
comments, and exit information.
A UNIX command that provides a little more information about
users that are logged in the system is the finger command.
?????????????????????????????????????????????????????????????????
? Command Format: finger [options] [user1] ?
? ?
? options - see on line manual for complete list ?
? ?
? user1 - login name ?
?????????????????????????????????????????????????????????????????
The finger command with no options will list the login name, full
name, terminal name, write status (an asterisk (*) before the
terminal name indicates that write permission is denied), idle
time, login time, office location, and phone number (if known)
for each user that is currently logged in the system.
Sample Session:
?????????????????????????????????????????????????????????????????
? $finger ?
? Login Name TTY Idle When Office ?
? Jwheeler Jim Wheeler ttyp0 16 Wed 10:26 MP ?
? mvlsdba Motor Veh Lic rt02190 16 Wed 09:25 d7160 ?
? teacher Teacher Acct *rt020b0 Wed 11:07 ?
? eholderf Eileen Holder rt021c0 1 Wed 11:03 ?
? dbowman Dale Bowman rt01150 Wed 08:58 ?
? $ ?
?????????????????????????????????????????????????????????????????
Workshop 1
This workshop will reinforce your understanding of the ideas
presented in Chapter 1. Each student is to complete the entire
workshop.
DESK EXERCISES
1. What two organizations first developed UNIX?
2. In what high level programming language is UNIX written?
3. What are some characteristics of UNIX?
4. What is Encore Computer Corporations implementation of UNIX
called?
5. What part of UNIX controls the details of the computer's
internal operations?
6. What part of UNIX allows the user to communicate with the
computer?
Continue on the next page
7. What is the name of the tree-like structure under which all
data is stored?
8. What is the name of the highest level directory?
9. What symbol represents the highest level directory?
10. What is the general syntax of a UNIX command?
11. What is the most common form for listing options on a
command line?
12. What character would you use to erase a character on the
command line?
13. What character terminates the execution of a command?
14. What is the default BourneShell prompt?
15. How can you control the flow of output to your monitor
screen?
1. What annex command is entered to make a connection to the
Multimax?
2. What is the UNIX command to change the password?
3. How long is your password valid?
4. How long do you have to wait before changing your password
again? Why?
5. What UNIX command is used to logout of the Multimax?
6. What is the command to logout of the annex?
COMPUTER EXERCISES
7. Login to the Multimax
a. What did you notice when you entered the password?
b. Can you see the password as you enter it?
c. What happens if you make a mistake while entering the
password?
8. What do you see once you have logged in? Write it here.
9. Enter the command which displays the man pages for the man
command. (Don't forget to control output to the screen.)
The first section is titled "NAME," what are the titles of
the other sections?
10. What are the options for the man command?
11. Enter the command to find out who (hint) is logged into the
system.
12. What command will give you more information about the
current users? Try it.
13. Logout of the Multimax and the Annex.
2. FILES
In UNIX, all data is organized in files. An ordinary file is a
memo, source code program or shell script. A shell script or
program source code can be viewed or edited from your terminal.
Other files contain binary data, like programs for the kernel;
these files cannot be viewed or edited on the terminal.
Peripheral devices such as disks, tape drives, printers, and
terminals are also assigned file names. Device files are
considered to be special files. They have 'special'
characteristics. Although input and output can be redirected to
and from a special file, do not attempt to display the contents
of a special file on your terminal.
3.1 File Access Modes
File access modes are the protections that can be assigned to
files. This protection can protect your files from unauthorized
reading or writing. You can even protect your files from
yourself (you can prevent accidental deletion).
There are three access modes for files:
r (read) read, examine, copy data in a file
w (write) modify, delete a file
x (execute) use the file as a command
Users with access to a file fall into one of three groups:
u (user) the file's owner
g (group) users in the same group
o (other) everybody else
The first output field of the ls -l command is a ten character
field. Characters two through ten describe the file access
modes. A typical access mode listing looks like:
rwxr-xr-x
Of the nine columns, the first three describe modes for the
file's owner, the next three for his group, and the last three
for everyone else. Within each group of three, the first column
describes read access mode, the second write, and the third
execute. A letter in a column indicates access granted, a dash
(-) indicates access denied.
Using the previous example, the user has r (read), w (write), and
x (execute) permissions. Members of the user's logical group can
read ® or execute (x). Everyone else has read ® and execute
(x) permissions, too. The effect of these permissions is that
the file's owner is the only one who can modify the file; but
everyone can examine, copy, or execute the file.
To change access modes on a file or directory, use the chmod
command.
?????????????????????????????????????????????????????????????????
? Command Format: chmod <access> <file1[filen]> ?
? ?
? access - access permissions ?
? file1[filen] - one or more files to change permissions ?
?????????????????????????????????????????????????????????????????
Access can be expressed in either of two forms:
- with letters: [ugo] [+-=] [rwx]
- with numbers: [0-7] [0-7] [0-7]
Let's look at the method of changing the file permissions with
letters. The letters u, g, and o represent user, group, and
others, respectively. The + (plus) sign means to add the
permission and the - (minus) sign means to remove the permission.
The = (equal) sign means to set the permissions as shown. Of
course, r,w, and x are read, write, and execute.
If, for illustration purposes, we created a file named file1 that
had the following permissions:
rw-rwxrwx
and you want to give yourself (user) execute permission and take
away others' (others' here means group and everyone else) write
permissions.
Sample Session:
?????????????????????????????????????????????????????????????????
? $chmod u+x,g-w,o-w file1 ?
? $ ?
?????????????????????????????????????????????????????????????????
Now if we use the ls -la command, and look at the file
permissions for file1, they will look like this:
rwxr-xr-x
If you want to set several protections at once use the equal
sign. The following example will set the permissions for the
user to read and execute.
Sample session:
?????????????????????????????????????????????????????????????????
? $chmod u=rx file1 ?
? $ ?
?????????????????????????????????????????????????????????????????
The second method of changing the permissions is to use the octal
digits (0-7). The octal digits 0 through 7 are represented in
binary in the following manner.
Octal Binary Corresponds to permissions
0 000 ---
1 001 --x
2 010 -w-
3 011 -wx
4 100 r--
5 101 r-x
6 110 rw-
7 111 rwx
Notice that every time a one digit (1) occurs in the binary
number the corresponding permissions are also set. Every time a
zero (0) occurs, the corresponding permission is denied. So to
change the file permissions in the previous example, this is the
command to enter:
Sample Session:
?????????????????????????????????????????????????????????????????
? $chmod 755 file1 ?
? $ ?
?????????????????????????????????????????????????????????????????
The first octal digit assigns user permissions of read, write and
execute. The second digit assigns the group permission to read
and execute. The last digit sets the others permission to read
and execute too.
3.2 Listing Contents of Directories
The ls command is used to display file names and their
characteristics. Since file names are stored in directories, ls
actually reads directory files. Executing ls with no flags or
arguments simply lists the names of the files that exist in your
current working directory. The initialization files will not be
listed.
????????????????????????????????????????????????????????????????
? Command Format: ls [options] [dir1[dirn]] ?
? ?
? options - see man pages for a complete list ?
? ?
? dir1[dirn] - one or more directory names ?
????????????????????????????????????????????????????????????????
The -a flag will cause the hidden (initialization) and all other
filenames to be displayed.
The -C flag causes the output to be changed from single-column to
multi-column display.
The -F flag adds a character to the end of each displayed
filename:
/ indicates a directory
* indicates the file is executable.
blank indicates a plain or ordinary file
The -l flag causes detailed information to be printed for files
in the directory. This information includes:
file type (directory, block special, character special,
fifo special, symbolic link, or ordinary file)
access modes
number of links
ownership
group affiliation
size in bytes
date and time of last modification
filename
Without a filename argument, ls displays information about the
current working directory. The output is automatically sorted
alphabetically by default.
Example:
.................................................................
. $ls .
.................................................................
The following example provides a long listing of the current
working directory.
Example:
.................................................................
. $ls -l .
.................................................................
This example shows the ls command with no arguments so it uses
the default, the current working directory. The argument could
be a relative or absolute directory name.
Sample session:
?????????????????????????????????????????????????????????????????
? $ls -la ?
? total 975 ?
? drwxrwxr-x 4 teacher class 2048 Jul 16 17.56 . ?
? drwxr-xr-x 60 root 1536 Jul 13 14:18 .. ?
? -rwx------ 1 teacher class 4210 May 1 08:27 .profile ?
? -rwxr-xr-x 1 teacher class 1948 May 12 13:42 memo ?
? $ ?
?????????????????????????????????????????????????????????????????
3.3 File Classifications
The file command will classify files according to their contents.
?????????????????????????????????????????????????????????????????
? Command Format: file [options] <file1[filen]> ?
? ?
? file1[filen] - one or more filenames to analyze ?
?????????????????????????????????????????????????????????????????
A few of the classifications that the file command displays are
shown below. The results of using the file command are not
always correct.
English text
ascii text
c program text
cannot stat
commands text
data
directory
empty
executable
Sample Session:
?????????????????????????????????????????????????????????????????
? $file speople ?
? speople: commands text ?
? $file test ?
? test: directory ?
? $file mail ?
? mail: data ?
? $ ?
?????????????????????????????????????????????????????????????????
By convention, files beginning with a dot (.) are called
initialization files or 'hidden files'. These files describe
your environment to the shell. They are sometimes called 'dot
files'.
By convention, files that end with:
.c are C source code programs
.f are Fortran source code programs
.o are object programs
.a are archive files
3.4 Displaying Files
The cat command displays the contents of a file. The command cat
is an abbreviation for catenate. This command will read each file
in sequence and write it to the monitor screen.
?????????????????????????????????????????????????????????????????
? Command Format: cat [options] [file1[filen]] ?
? ?
? options - see man pages for a complete list ?
? ?
? file1[filen] - one or more file names ?
?????????????????????????????????????????????????????????????????
If no filename is given, or the argument - is encountered, cat
reads from standard input.
Sample session:
.................................................................
. $cat .
.................................................................
This is the simpliest example but not very exciting. The cat
command will get its input from the keyboard. Everything that is
typed will be displayed on the monitor.
If an argument is given to the cat command that file will be
displayed on the monitor.
Sample session:
?????????????????????????????????????????????????????????????????
? $cat main.c ?
? main () ?
? { ?
? printf ("hello from main!\n\n"); ?
? printf ("calling function1!\n\n"); ?
? funct1(); ?
? printf ("back from function1!\n\n"); ?
? printf ("calling function2!\n\n"); ?
? funct2(); ?
? printf ("that's it!\n\n"); ?
? } ?
? $ ?
?????????????????????????????????????????????????????????????????
Several files can be displayed on the monitor one after the other
by separating the filenames with a space.
Sample session:
?????????????????????????????????????????????????????????????????
? $cat main.c main.f ?
? main () ?
? { ?
? printf ("hello from main!\n\n"); ?
? printf ("calling function1!\n\n"); ?
? funct1(); ?
? printf ("back from function1!\n\n"); ?
? printf ("calling function2!\n\n"); ?
? funct2(); ?
? printf ("that's it!\n\n"); ?
? } ?
? program calling ?
? write(6,100) ?
? 100 format('Hello from main!',/) ?
? write(6,110) ?
? 110 format(' Calling subroutine1!',/) ?
? call sub1 ?
? write(6,120) ?
? 120 format(t15' Back from subroutine1!',/) ?
? write(6,130) ?
? 130 format(' Calling subroutine2!',/) ?
? call sub2 ?
? write(6,140) ?
? 140 format(t15' Back from subroutine2!',/) ?
? write(6,150) ?
? 150 format(' Thats all, folks!') ?
? end ?
? $ ?
?????????????????????????????????????????????????????????????????
If the file contains more lines than can be displayed on the
screen the display will continue to scroll until the last line
has been displayed then the prompt will be redisplayed. This can
be a problem if you intend to read the text. Be prepared to stop
the screen so it can be read.
The pg command displays the contents of a file one screen at a
time. It allows the user to perform string searches and to
scroll backwards.
?????????????????????????????????????????????????????????????????
? Command Format: pg [options] [file1[filen]] ?
? ?
? options - see man pages for a complete list ?
? ?
? file1[filen] - one or more files to paginate ?
? ?
?????????????????????????????????????????????????????????????????
Sample session:
??????????????????????????????????????????????????????????????????????????????
? ?
? $pg memo ?
? What's Happening ?
? by Pam Hajny ?
? Denver Office ?
? ?
? With IRM Training: ?
? ?
. A Reclamation-wide workshop was held in early October to .
. .
. .
? three groups; CYBER, VAX, and other (PC/LAN, scientific, ?
? : ?
? ?
??????????????????????????????????????????????????????????????????????????????
Twenty three lines of the file will appear and the : (colon)
prompt will appear on the last line. To have the next twenty
three line of the file appear, simply press (Ret). If you don't
want to see anymore of the file, enter a q (for quit) and the
shell prompt will be redisplayed.
The following UNIX command is useful for viewing the end of a
file without having to display the entire file.
?????????????????????????????????????????????????????????????????
? Command Format: tail [options] [file1] ?
? ?
? options - see man pages for a complete list ?
? ?
? file1 - the file to display, if none is given use ?
? standard input ?
?????????????????????????????????????????????????????????????????
The tail command displays the last 10 lines of file by default.
The tail command accepts a -N flag to display the last N lines.
Sample Session:
??????????????????????????????????????????????????????????????????????????????
? $tail memo ?
? data communication between the ASC IBM and other Reclamation computers. ?
? Asynchronous communication can be accomplished with the same terminals ?
? we use for other computer tasks, over the same lines and through the MICOM ?
? port selectors. Currently, host-to-host communications is accomplished ?
? over a line between the IBM and the CYBERs. The software that supports ?
? this communication is called NJEF. Although the capability has been there ?
? for some time, we have recently been working with ASC personnel to ?
? improve its reliability and accessibility. For CYBER users, there is ?
? an NJEF Users' Guide available which can be requested through the Hotline ?
? (303) 236-4567. ?
? $ ?
??????????????????????????????????????????????????????????????????????????????
3.5 Removing Files
The rm command will remove the entries for one or more files from
a directory. If an entry was the last link to the file, the file
will be destroyed. Removal of a file requires write permission
to the directory itself, but neither read nor write permission to
the file itself. The format for the rm command is:
????????????????????????????????????????????????????????????????
? Command Format: rm [options] <file1[filen]> ?
? ?
? options - see man pages for a complete list ?
? ?
? file1[filen] - one or more files to remove ?
????????????????????????????????????????????????????????????????
Sample session:
?????????????????????????????????????????????????????????????????
? $ls ?
? memo ?
? tdata ?
? subdir ?
? $rm memo ?
? $ls ?
? tdata ?
? subdir ?
? $ ?
?????????????????????????????????????????????????????????????????
The file memo has been deleted from the current working
directory.
Multiple files can be deleted by separating the filenames with a
space.
Sample session:
?????????????????????????????????????????????????????????????????
? $ls ?
? memo ?
? tdata ?
? subdir ?
? $rm memo tdata ?
? $ls ?
? subdir ?
? $ ?
?????????????????????????????????????????????????????????????????
3.6 Printing Files
The lp command routes a file to a printer.
?????????????????????????????????????????????????????????????????
? Command Format: lp [-d<dest>] [-n<number>] [file1[filen]] ?
? ?
? dest - destination (default set by administrator) ?
? ?
? number - number of copies (default is 1) ?
? ?
? file1[filen] - one or more files to be printed ?
?????????????????????????????????????????????????????????????????
If no file name is mentioned the standard input is assumed. The
filename dash (-) stands for standard input and may be supplied
in conjunction with named files. The order in which the
filenames appear is the order in which they will be printed.
The printers in Denver have the following destination names:
Mannesman 910 laser printer - mtlzr
Mannesman 600 line printer - mt_600 (Denver default)
If no specific printer is given the default printer will be
selected. The following example will print one copy (default) of
the file called test_285 to the line printer (default).
Sample session:
?????????????????????????????????????????????????????????????????
? $lp test_285 ?
? request id is mt_600-1271 (1 file) ?
? $ ?
?????????????????????????????????????????????????????????????????
It is possible to specify the printer as shown in the following
example. In this case, we specified the default printer.
Sample Session:
?????????????????????????????????????????????????????????????????
? $lp -dmt_600 test_286 ?
? request id is mt_600-1272 (1 file) ?
? $ ?
?????????????????????????????????????????????????????????????????
To print two copies of a file called test_287 on the laser
printer in Building 53 in Denver, enter the following command:
Sample Session:
?????????????????????????????????????????????????????????????????
? $lp -dmtlzr -n2 test_287 ?
? request id is mtlzr-1273 (1 file) ?
? $ ?
?????????????????????????????????????????????????????????????????
3.7 Print Status
The lpstat command will print information about the current
status of the printer system.
?????????????????????????????????????????????????????????????????
? Command Format: lpstat [options] ?
? ?
? options - see man pages for a complete list ?
? ?
?????????????????????????????????????????????????????????????????
If no options are given, the lpstat command will print the status
of all requests made to lp by the user.
Sample Session:
?????????????????????????????????????????????????????????????????
? $lpstat ?
? mtlzr-1274 teacher 22560 Jul 16 09:05 on mtlzr ?
? $ ?
?????????????????????????????????????????????????????????????????
The first field is the remote id of the print job. The username
is next and the size (in bytes) of the print file. The date and
time are next and finally the name of the printer.
One of the options available is -t. This option will print all
of the printer status information.
Sample Session:
?????????????????????????????????????????????????????????????????
? $lpstat -t ?
? scheduler is running ?
? system default destination: mt_600 ?
? device for mt_600: /dev/rlp000 ?
? device for mtlzr: /dev/rt0002 ?
? mt_600 accepting requests since Sep 19 16:09 ?
? mtlzr accepting requests since Sep 19 16:43 ?
? printer mt_600 is idle. enabled since Jul 3 16:52 ?
? printer mtlzr is idle. enabled since Jul 3 16:51 ?
? $ ?
?????????????????????????????????????????????????????????????????
This is an example of the kinds of information available from the
lpstat command.
3.8 Canceling Print Jobs
The cancel command will cancel printer requests made by the lp
command. The command line arguments can be either request id's
(these are returned by the lp command) or the printer name. If
you specify the request id, the cancel command will stop the job
even if it is currently printing. If you specify the printer
name, the job currently being printed will be canceled. In
either case, the cancellation of a request that is currently
printing will free the printer to print the next request.
?????????????????????????????????????????????????????????????????
? Command Format: cancel <[ids] [printer]> ?
? ?
? ids - request ids (returned by lp command) ?
? ?
? printer - printer name ?
?????????????????????????????????????????????????????????????????
Sample Session:
?????????????????????????????????????????????????????????????????
? $lp -dmt_600 contest ?
? request id is mt_600-1280 (1 file) ?
? $cancel mt_600-1280 ?
? request "mt_600-1280" canceled ?
? $ ?
?????????????????????????????????????????????????????????????????
3.9 Copying Files
A user may make a copy of a file if he has read access to that
file. The cp command can be used to copy the contents of one
file to another.
?????????????????????????????????????????????????????????????????
? Command Format: cp <file1[filen]> <target> ?
? ?
? file1[filen] - one or more source files ?
? ?
? target - file or dirname ?
? ?
? file1 and target cannot be the same and ?
? if the target is a file its' contents are ?
? destroyed. ?
? ?
? If target is a directory, then the contents ?
? of the source file(s) is copied to that ?
? directory. ?
? ?
?????????????????????????????????????????????????????????????????
Sample Session:
?????????????????????????????????????????????????????????????????
? $cp contest memo ?
? $ ?
?????????????????????????????????????????????????????????????????
This will cause a copy of the file contest to be made into a file
named memo. If memo doesn't exist, it will be created. If it
already exists, it will be written over. The cp command is
nondestructive; that means that the source file will remain
intact.
The cp command can also be used to copy several files into
another directory.
Sample Session:
?????????????????????????????????????????????????????????????????
? $cp file1 file2 /user0/teacher ?
? $ ?
?????????????????????????????????????????????????????????????????
A copy of file1 and file2 has been sent to the directory (in this
case, the target directory) /user0/teacher. The user of cp will
own the newly copied files.
3.10 Moving Files
A user may move a file only if he has write access to that file.
The mv (move) command can be used to rename one file.
?????????????????????????????????????????????????????????????????
? Command Format: mv <file1[filen]> <target> ?
? ?
? file1[filen] - one or more source files ?
? ?
? target - file or dirname ?
? ?
? file1 and target cannot be the same and ?
? if the target is a file its' contents are ?
? destroyed. ?
? ?
? If target is a directory, then the contents ?
? of the source file(s) are moved to that ?
? directory. ?
? ?
?????????????????????????????????????????????????????????????????
Sample Session:
?????????????????????????????????????????????????????????????????
? $mv contest memo ?
? $ ?
?????????????????????????????????????????????????????????????????
This will have the effect of changing the name of the file
contest into memo. The permissions on the file will remain the
same. The move command is destructive. That means the source
file no longer exists.
The mv command can also be use to move files from one directory
to another.
Sample Session:
?????????????????????????????????????????????????????????????????
? $mv file1 file2 /user0/teacher ?
? $ ?
?????????????????????????????????????????????????????????????????
The files, file1 and file2, have been sent to the directory
/user0/teacher. They have been "moved" and no longer reside in
the current directory. The owner remains the same when a file is
moved.
Workshop 3
This workshop will reinforce your understanding of the topics
presented in this chapter. Login to the Multimax using the
username and password given to you by the instructor. Each
student should complete the entire workshop. You might need to
work in a team on the computer exercises.
DESK EXERCISES
1. List four types of files.
2. What does the file command do?
3. The ls command will display the contents of the current
working directory. What does the -F option do?
4. What command is used to display the contents of an ordinary
file?
5. What command would you use to append one file to the end of
another?
6. What is the lp command?
Continue on the next page
7. How can you find out the status of your print job?
8. What command would you enter to cancel a print job called
mt_600-1131?
9. What command will copy the contents of one file to another?
10. What does mv do?
11. What do the following file protections indicate?
rwx------
rwxr-xr-x
---------
rwxr--r--
Continue on the next page
COMPUTER EXERCISES
12. Log into the Multimax.
13. Execute the file command on the files listed below. Record
the output in the space provided.
a. .profile
b. /bin/vax
c. /dev/console
14. Which of the above files is readable?
15. Enter the command to display the contents of the current
working directory. Hint: ls
a. How many files are listed?
b. Type ls -a
c. How many entries are listed?
Continue on the next page
d. Which entries were not listed in your original output
of ls?
16. How does the output of ls -a and ls -Ac differ?
Try it.
17. How many fields are displayed for each entry when you
execute ls -l? What are the fields?
18. What are the current permissions on .profile?
19. Change permissions on .profile so that no one (including
you) has any access to the file.
(Hint: Use the chmod command)
20. Without changing the permissions, list the contents of the
file named .profile to the screen.
What happened? Why?
Continue on the next page
21. Change the permissions on .profile to
u - read, write, execute
g - read
o - read
22. Type cat .profile. What happened? Do you know why?
23. Enter pg memo. What does this command do?
24. Send one copy of the file called memo to the laser printer.
25. Logout of the Multimax and the Annex.
NOTES
?????????????????????????????????????????????????????????????????
4. DIRECTORIES
A directory is a file whose sole job is to store file names and
related information. All files, whether ordinary, special, or
directory, are contained in directories.
The directory in which you find yourself when you first login is
called your home directory. You will be doing much of your work
in your home directory and subdirectories that you'll be creating
to organize your files.
4.1 Absolute/Relative Pathnames
As we saw earlier, directories are arranged in a hierarchy with
root (/) at the top. The position of any file within the
hierarchy is described by its pathname. Elements of a pathname
are separated by a /. A pathname is absolute if it is described
in relation to root, so absolute pathnames always begin with a /.
These are some example of absolute filenames.
/etc/passwd
/users/sjones/chem/notes
/dev/rdsk/Os3
A pathname can also be relative to your current working
directory. Relative pathnames never begin with /. Relative to
user sjones' home directory, some pathnames might look like this:
chem/notes
personal/res
To determine where you are within the filesystem hierarchy at any
time, enter the command to print the current working directory.
?????????????????????????????????????????????????????????????????
? Command Format: pwd ?
?????????????????????????????????????????????????????????????????
Sample Session:
?????????????????????????????????????????????????????????????????
? $pwd ?
? /user0/teacher ?
? $ ?
?????????????????????????????????????????????????????????????????
Notice that this is an absolute pathname. This is the pathname
of the current working directory.
4.2 Creating Directories
Directories are created by the following command:
?????????????????????????????????????????????????????????????????
? Command Format: mkdir [options] <dirname> ?
? ?
? options - see man pages for a complete list ?
? ?
? dirname - name of the new directory (absolute or ?
? relative pathname). ?
?????????????????????????????????????????????????????????????????
If the option to change permission mode is not given, the
directory will have default permissions set to read,write,execute
for the user and read and execute for group and others. The
files . (dot) and .. (dot dot) are created automatically. In
order to create a sub-directory, you must have write permission
on the parent directory. The owner id and the group id are set
to the real users id and group id, respectively.
4.3 Removing Directories
Directories can be deleted using the rmdir command.
?????????????????????????????????????????????????????????????????
? Command Format: rmdir [options] <dirname> ?
? ?
? options - see man pages for a complete list ?
? ?
? dirname - the directory to remove, it must be empty. ?
? ?
?????????????????????????????????????????????????????????????????
Sample Session:
?????????????????????????????????????????????????????????????????
? $pwd ?
? /user0/teacher ?
? $ls -la ?
? total 5 ?
? drwxr-xr-x 2 teacher class 512 Jul 18 08:12 . ?
? drwxrwxr-x 5 root root 2048 Jul 1 13:14 .. ?
? $rmdir teacher ?
? rmdir:teacher:Directory does not exist ?
? $ ?
?????????????????????????????????????????????????????????????????
Normally, directories are deleted using the rmdir command.
Before the directory can be removed, it must be empty; that is,
it must not contain any files. Notice that in the above example
two files are present, . (dot) and .. (dot). Remember, these
refer to the current working directory and its parent. They
cannot be removed.
Sample Session:
?????????????????????????????????????????????????????????????????
? $rmdir . ?
? rmdir: .: Can't remove current directory or .. ?
? $ ?
?????????????????????????????????????????????????????????????????
For the purposes of deleting a directory, the directory is empty
if it contains only two files, namely . (dot) and .. (dot dot).
4.4 Changing Directories
To "move around" in the filesystem, use the cd (change directory)
command.
?????????????????????????????????????????????????????????????????
? Command Format: cd [dirname] ?
? ?
? dirname - If not specified, the value of the $HOME ?
? shell variable will be used as the new ?
? current working directory. ?
? ?
? If the directory given is an absolute pathname ?
? that directory is the new current working ?
? directory. A relative pathname can also be ?
? given. ?
?????????????????????????????????????????????????????????????????
Sample Session:
?????????????????????????????????????????????????????????????????
? $cd /user0/teacher ?
? $pwd ?
? /user0/teacher ?
? $ ?
?????????????????????????????????????????????????????????????????
The current working directory is now /user0/teacher.
Sample Session:
?????????????????????????????????????????????????????????????????
? $cd memos ?
? $pwd ?
? /user0/teacher/memos ?
? $ ?
?????????????????????????????????????????????????????????????????
This command will look for a subdirectory called memos under the
current working directory. If it is found, it will become the
new working directory; otherwise, an error will occur.
Error messages beginning with "cannot access file..." often
indicate that the pathname is incorrect or misspelled.
4.5 Renaming Directories
The mv (move) command can also be used to rename a directory.
?????????????????????????????????????????????????????????????????
? Command Format: mv <dirname> <target> ?
? ?
? dirname - name of the source directory ?
? target - target directory name ?
?????????????????????????????????????????????????????????????????
Sample Session:
?????????????????????????????????????????????????????????????????
? $mv users newusers ?
? $ ?
?????????????????????????????????????????????????????????????????
This will have the effect of changing the name of the directory
users into newusers. The permissions on the directory will
remain the same.
NOTE: All files and subdirectories in the directory newusers
now have new absolute pathnames.
4.6 The directories . (dot) and .. (dot dot)
The filename . (dot) represents the current working directory;
and the filename .. (dot dot) represent the directory one level
above the current working directory, often referred to as the
parent directory. If we enter the command to show a listing of
the current working directories files and use the -a option to
list all the files and the -l option provides the long listing,
this is the result.
Sample Session:
?????????????????????????????????????????????????????????????????
? $ls -la ?
? total 975 ?
? drwxrwxr-x 4 teacher class 2048 Jul 16 17.56 . ?
? drwxr-xr-x 60 root 1536 Jul 13 14:18 .. ?
? ---------- 1 teacher class 4210 May 1 08:27 .profile ?
? -rwxr-xr-x 1 teacher class 1948 May 12 13:42 memo ?
? $ ?
?????????????????????????????????????????????????????????????????
The ls -la command displays access modes, number of links, the
owner, the group, size, etc. of files in a directory; but also
displays the characteristics of the current working directory and
its parent. The first entry is the entry for the current
directory. The owner is teacher and the group is class. The
second entry is the parent directory. It is one level up from
the current working directory. It is owned by the root
directory.
Instead of asking for information on all of the files in a
directory, you can request just the information on the current
working directory.
Sample Session:
?????????????????????????????????????????????????????????????????
? $ls -ld ?
? drwxrwxr-x 4 teacher class 2048 Jul 16 17:56 . ?
? $ ?
?????????????????????????????????????????????????????????????????
The response from the command simply shows the long information
for the current working directory . (dot).
Information can also be obtained for the parent of the current
working directory by using its name as an argument.
Sample Session:
?????????????????????????????????????????????????????????????????
? $ls -ld .. ?
? drwxr-xr-x 60 root root 1536 Jul 13 14:18 .. ?
? $ ?
?????????????????????????????????????????????????????????????????
Here's the long list of the current working directories parent.
(.. is the shorthand representation of the current working
directories parent)
Both of the directory names . (dot) and .. (dot dot) can be used
as arguments to commands. To change the parent of the current
working directory into the current working directory, the command
is:
Sample Session:
?????????????????????????????????????????????????????????????????
? $pwd ?
? /user0/teacher ?
? $cd .. ?
? $pwd ?
? /user0 ?
? $ ?
?????????????????????????????????????????????????????????????????
The current working directory is the former parent.
This is all very interesting but what good is it? You can
specify the current working directory or its parent without
typing the entire absolute pathname. It can also be handy when
giving arguments to UNIX commands.
Why are the pathnames sjones/chem and ./sjones/chem equivalent?
4.7 Directory Access Modes
Directory access modes are listed and organized in the same
manner as any other file. There are a few differences that need
to be mentioned.
4.7.1 Read
Access to a directory means that the user can read the contents.
The user can look at the filenames inside the directory.
4.7.2 Write
Access means that the user can add or delete files to the
contents of the directory.
4.7.3 Execute
Executing a directory doesn't really make a lot of sense so think
of this as a traverse permission. This access allows the user to
reference the directory name in a command. The reference is not
necessarily explicit, since the shell deduces the absolute
pathname of a command from the user's environment. For example,
the shell knows that the full pathname of the ls command is
/bin/ls. A user must have execute access to the bin directory in
order to execute ls.
If traverse permissions are denied, others cannot change to it or
through it. Another user can't do a cd to the protected
directory or any subdirectory beneath it.
IN CLASS QUIZ
??????????
? / ?
??????????
?
?????????????????????????????????????????????????????????????????????????????????????
? ? ? ? ?
???????????? ??????????? ??????????? ??????????? ???????? ???????????
? bin ? ? tmp ? ? etc ? ? mnt ? ? l ? ? dev ?
???????????? ??????????? ??????????? ??????????? ???????? ???????????
?
???????????????????????????????????????????????????????????????????????????????????????????????????????????
? ? ? ?
????????????? ??????????? ??????????? ???????????
? Uni1 ? ? Uni2 ? ? Uni3 ? ? Uni4 ?
????????????? ??????????? ??????????? ???????????
{1} ???????????????????????????? ?????????????????? ?????????????????????? ??????????????
???????????? ????????????? ??????????? ????????????? ????????????? ??????????? ??????????? ???????? ??????????? ???????????
? filea ? ? fileb ? ? Dira ? ? filea ? ? Filea ? ? file1 ? ? File2 ? file3 ?{5} ? Dir1 ? ? Dir2 ?
???????????? ????????????? ??????????? ????????????? ????????????? ??????????? ??????????? ???????? ??????????? ???????????
? ? ? ? ?
???????????????????????????? ? ? ?????????????? ?
???????????? ????????????? ??????????? ????????????? ??????????? ??????????? ??????????? ???????????
? filea ? ? Dirb ? ? fileb ? {2} {3} ? filea ? ? Filea ? }? File1a ? ? file1b ? ? Dir2a ?
???????????? ????????????? ??????????? ????????????? ??????????? ??????????? ??????????? ???????????
? ?
Write the complete pathname for the 5. ________________________________ ??????????? ??????????????? {7}
files numbered above. {4} ? filea ? ??????????? ???????????
6. ________________________________ ??????????? ? File2aa ? ? file2ab ?
1. _______________________________ 8. You are in /mnni1 and want #1. ??????????? ???????????
7. ________________________________
2. _______________________________ ___________________________________
3. _______________________________ Write the minimum pathname needed for 9. You are in /mnni3/File2 and want #4
each of the following:
4. _______________________________ ___________________________________
4.7.4 Typical Root Directory
????????????????????????????????????????????????????????????????????????????????????????????
? $ ls -FC / ?
? ?
? ?
? Student/ bin/ lib/ stand/ u2/ user2/ ?
? ?
? Students/ bad/ lisp/ tmp/ unix* usr/ ?
? ?
? Support/ dev/ lost+found/ tmp.sh unix.bak* usr2/ ?
? ?
? etc/ mnt/ tmp1/ unix.test* usr3/ a.out* ?
? ?
? foo rel_notes tmp2/ user0/ install/ shlib/ ?
? ?
? u1/ user1/ ?
????????????????????????????????????????????????????????????????????????????????????????????
NOTES
?????????????????????????????????????????????????????????????????
Workshop 4
This workshop will reinforce your understanding of the topics
presented in this chapter. Login to the Multimax using the
username and password from the previous workshop. All students
should complete the entire workshop. You may need to work in a
team on the computer exercises.
DESK EXERCISES
1. What is a directory?
2. What is an absolute path name?
3. What is a relative path name?
4. What command will create a directory?
5. What command will remove a directory?
6. What command is used to change from one directory to
another?
7. How would you change the name of a directory?
Continue on the next page
8. What do the files . (dot) and .. (dot dot) represent?
9. What does execute permission on a directory mean?
COMPUTER EXERCISES
10. Login to the Multimax.
11. What is the absolute pathname of your current working
directory? Hint: pwd
12. Type cd etc
What message do you get? Can you explain why?
13. Type cd /etc
What is your current working directory? Why did this
happen?
14. Enter the command that will return you to your home
directory.
Continue on the next page
15. Enter the command that will change to your current working
directories parent.
16. List the contents of your current working directory
17. List the permissions, ownership, size, etc. of your current
directories parent.
18. Enter the command to change to your home directory. Create
a new subdirectory with a name of your choice.
19. Change the current working directory to the subdirectory you
just created.
20. Rename the subdirectory to Student. Is this the same
subdirectory as everyone else in the class? Why?
21. Change to your home directory and delete the subdirectory
Student.
22. Logout of the Multimax and the Annex.
NOTES
?????????????????????????????????????????????????????????????????
5. COMMUNICATION UTILITIES
This chapter will deal with the utilities that allow one user to
communicate with another. Some of these utilities require the
other user to be logged in and others do not.
The mail utility can be used to send messages to one or more
users. It is not necessary for the user that is receiving the
message to be logged in. The mail utility delivers the message
to a file belonging to the recipient. The user will be notified
that a mail message exists. Messages can be saved or deleted and
a reply sent.
The talk utility is an interactive session that allows each user
to send message simultaneously to each other. Both users must be
currently logged in for this utility to work.
The write utility is a one-way communication. It allows you to
send a message to another user. The user must be logged in and no
reply is possible.
5.1 Sending Electronic Mail
The basic command line format for sending mail is:
?????????????????????????????????????????????????????????????????
? Command Format: mailx [options] [user1[usern]] ?
? ?
? options - see man pages for a complete list ?
? ?
? user1[usern] - one or more users to get the mail ?
? message ?
? ?
?????????????????????????????????????????????????????????????????
The username is the name assigned by the system administrator to
a user on the UNIX system (for example, rharding). The username
can also include a system name if the recipient is on another
UNIX system that can communicate with the sender's (for example,
sys2!rharding). Let's assume that the recipient is on the local
UNIX system.
Sample Session:
?????????????????????????????????????????????????????????????????
? $mailx rharding(Ret) ?
? Subject: ?
?????????????????????????????????????????????????????????????????
Now enter the subject of your message followed by a (Ret). The
cursor will appear on the next line. Simply start typing the
message. There is no limit to the length of a message. When you
have finished, send it by typing Ctrl-D on a new line.
Sample Session:
?????????????????????????????????????????????????????????????????
? $mailx rharding(Ret) ?
? Subject: Work schedule(Ret) ?
? Please check the bulletin board(Ret) ?
? for the new work schedule.(Ret) ?
? Ctrl-D ?
? $ ?
?????????????????????????????????????????????????????????????????
The shell prompt on the last line indicates that the message has
been queued (placed in a waiting line) and will be sent.
5.2 Reading Mail
To read your mail enter:
Example:
.................................................................
. $mailx .
.................................................................
Executing this command places you in the command mode of mailx.
If there are no mail messages waiting to be read, you will see
the following message on the screen:
Sample Session:
?????????????????????????????????????????????????????????????????
? $mailx ?
? No mail for teacher ?
? $ ?
?????????????????????????????????????????????????????????? | |