Utilities

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.

The Unix O/S can be divided into three parts:

Kernel
Memory resident part of the operating system. It communicates directly with the hardware. The user never interacts directly with the kernel directly.
Utilities
About 200 standard programs that perform functions universally required by users. Most operating system services are performed by the utilities in Unix.
Shell and Time-sharing Utilities
The highest level of the system software. An interactive program that interprets and executes commands. It communicates directly with the user and makes calls to the utilities or kernel.


Generic Utilities

Contents

File System
Navigation
File and directory naming
Basic utilities

File System

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:
Hierarchy
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.)

Navigation

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 user. 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

File and directory naming

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
relative
If just the name itself is given without any special prefixes (such as /, ., .., ~) then it refers to the file in the current working directory.

Basic utilities

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

Unix Utilities

Contents

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:
man pages
File name globbing
Command history
Summary

File copying:

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

File renaming:

mv [options] original new
The options include
-i interactive confirmation of overwrites
-f force a move
For more information, man mv

File removal

rm [options] files...

For more information, man rm

Printing a file:

lpr [options] files...

For more information, man lpr

Displaying contents of a file:

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

Listing contents of a directory:

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

Changing directories:

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

Showing current working directory:

pwd

Some shells perform this function directly (since they already have this information), some leave it to a program.
For more information, man pwd

Making a new directory:

mkdir directory...

For more information, man mkdir

Removing a directory:

rmdir directory...

For more information, man rmdir

man pages

All the Unix command information is kept on line. Select the manual pages from the system menu. A typical man page looks like:

An alternative to man that is available under the X Window System is xman

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

File name globbing

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. 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 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

Command history

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. You can also use the arrow keys to move through the command list, and to edit a command.

Summary

This lecture has looked at common utilities available under Unix. They include
Home Home
Jan Newmarch (http://jan.newmarch.name)
jan@newmarch.name Last modified: Wed Mar 7 20:17:40 EST 2001