This lecture gives a general view of some of the utilities that
are common in Operating Systems, and gives more details on the
ones available in Unix.
Files are stored on devices such as hard and floppy disks. The details of
how this may be done is considered in a later
lecture.
The O/S defines a
file system on
the devices. Many O/S use a
hierarchical file system:
A directory is a file that keeps a list of other files. This list is the set
of children of that directory node in the file system. A directory cannot hold
any other kind of data.
On MSDOS a file system resides on each floppy or partition of the hard disk.
The device name forms part of the file name.
On Unix there is a single file system. Devices are
mounted into this file system.
(Use the command mount
to see this.)
To locate your position as a user of the file system, there is the concept
of your
current working directory.
Unix only has one working directory per
command shell. MSDOS has one per device.
MSDOS maintains a current file system (drive).
Unix has a per user home directory.
You can change the current working directory by using the command
cd new-directory
An individual node of the file system has its own name. Naming conventions
differ between O/S's. In MSDOS, a name is constructed of upto 8+3 characters.
Windows95 uses tricks on top of the MSDOS file system to give ``long
file names'' of upto 255 characters.
In ``standard Unix'' (POSIX) a name may consist of upto 256 characters.
The full file names are constructed by concatenating the directory names
from the root down to the file, with some special separator between names.
This is known as absolute path naming. In MSDOS, the full path name also
includes the drive name.
Example:
MSDOS
C:\expsys\lectures\search.txt
Example:
Unix
/usr/usrs/os
/usr/usrs/os/myfile
Relative naming means that files are named from some special directory:
. current directory (Unix and MSDOS)
.. parent directory (Unix and MSDOS)
~ home directory (some Unix shells)
~user
home directory of user (some shells)
Example:
Unix
~fred/../bill/dir1/./../file1
If just the name itself is given without any special prefixes (such as /, .,
.., ~) then it refers to the file in the current working directory.
An O/S - to the user - consists of the O/S itself plus a command interpreter
and a set of programs that perform common operations. This set of operations
include
-
File copying
-
File renaming
-
File removal
-
Printing a file
-
Displaying contents of a file
-
Listing contents of a directory
-
Changing directories
-
Showing current working directory
-
Making a new directory
-
Removing a directory
cp [options] original new
cp [options] files... dir
The options include
-i interactive confirmation of overwrites
-f force a copy
-R recursively copy to a directory
For more information,
man cp
mv [options] original new
The options include
-i interactive confirmation of overwrites
-f force a move
For more information,
man mv
rm [options] files...
For more information,
man rm
lpr [options] files...
For more information,
man lpr
cat files...
more files...
cat
concatenates all the files together and sends the result to
standard output
ie it displays the contents to the screen.
Like
cat /etc/hosts
For more information,
man cat
more
displays a page at a time.
Move to the next page by pressing the space
bar.
more /etc/hosts
For more information,
man more
less
displays a page at a time.
Move to the next page by pressing the space
bar.
less /etc/hosts
For more information,
man less
ls [options] files...
ls shows information about the files, or the contents of directories.
ls /tmp
There
are a large number of options for ls:
-l show in long format
-a show ``hidden'' files (starting with .)
-F show type information too
For more information,
man ls
cd [directory]
If no directory is given, change back to the home directory.
If the argument is a single '-' (cd -), changes back to the last
directory you moved from.
Note: the concept
of current working directory for a user in Unix is actually maintained by the
shell, so the shell actually performs this function itself, rather than by
separate programs.
For more information,
man cd
pwd
Some shells perform this function directly (since they already have this information),
some leave it to a program.
For more information,
man pwd
mkdir directory...
For more information,
man mkdir
rmdir directory...
For more information,
man rmdir
All the Unix command information is kept on line. Select the manual pages
from the system menu.
-
The user-level commands are all in Section One.
-
Section Two is the Unix Application Programmer's Interface,
API (ie C functions directly
supported by Unix).
-
Section Three is library extensions to these.
-
Section Four
defines devicesknown to Unix.
-
Section Five defines common file formats.
-
Sections
Local and New are for stuff we have added to our local system.
The format is
-
Name
-
what the command is called
-
Synopsis
-
how it is used
-
Description
-
what it does
-
Options
-
what the options are
-
See Also
-
related commands
-
Files
-
files used
-
Bugs
-
known bugs
For more information,
man man
An alternative to
man
that is available under the X Window
System is
xman
When you type a line of input to any of the Unix shells, it goes through a
number of steps. The line is first globbed. This expands out patterns. After
this, a check is made to see if the first word is a command special to the
shell.
- If it is, the command is executed directly by the shell (examples are
cd, pwd).
- If not, a list of directories defined by the shell's PATH variable
is searched for the command.
When a match is found, the command from that directory
is executed.
- If no match is found, you get a warning message from the shell.
Words in the command that contain the characters ?
or * are treated as patterns
for filenames. The word is expanded into a list of file names, according to
the type of pattern. The following expansions are made by most shells,
including bash:
* matches any string (including null)
? matches any single character
[abcdefg] matches any single character a-g
[a-f] matches any single character a-f
As a special case, any . beginning a word must be matched explicitly.
Example:
The directory contains the files
tmp
tmp1
tmp2
tmp10
The pattern *1* matches the files tmp1 and tmp10.
The pattern t??? matches tmp1 and tmp2
The pattern t*[0-9] matches tmp1, tmp2 and tmp10
bash has a command history for convenience. The list of previous commands
may be obtained by
history
Entering the command
!n
(n is an integer) will re-execute the nth command.
Entering the command
!xyz
(xyz is some string) will re-execute the last command startin with xyz. You can also use the arrow
keys to move through the command list, and to edit a command.
This lecture has looked at common utilities available under Unix.
They include
- cd
- cp
- mv
- rm
- lpr
- pwd
- mkdir
- rmdir
- man and xman
- history