PAGEFLOP
FORWARD
SELECTOR
SELAGAIN
WRONGSEL
YOUR SELECTION IS NOT IN THE 0 - #SELIMIT RANGE Please try again
AANVANG
Copyright CourseWare Technologies Inc. 1985-88
Lesson - 2
OPTIMIZING SYSTEM ADMINISTRATION
MENU
Optimization|Topics to Learn|2-0|13,46
# Topic
--- -------
1 - Introduction
2 - Choosing Among Shells
3 - Files and Directories That Grow
4 - Using the find Command
5 - Reorganizing File Systems
6 - Keeping Directories Small
7 - Using fsck Effectively
8 - Communicating with Users
9 - Using the calendar Command
10 - Lesson Review
0 - Return to the Main Menu
P1
Optimization|Introduction|2-1.1|11,57
Before proceeding with the material in this lesson,
let us remind you that being a system administrator
carries a lot of responsibility. Because the system
administrator's actions affect the entire system and
all of its users, one must understand the commands
and their consequences very well before applying them.
The authors do not expect you to master all of the
procedures in two days, but they certainly hope that this
tutorial will substantially reduce your learning time.
P2
Optimization|Choosing Among Shells|2-2.1|11,54
As you know, the Shell is a programming language, a
command language and a command interpreter that allows
for both interactive an non-interactive use.
Your UNIX System is most likely supplied with
at least two shells: the Bourne Shell, sh, and the
Berkeley C-Shell, csh. Some systems may also have
the visual shell, vsh, the Korn Shell ksh, and the
restricted shell, rsh. The Shell each user gets at
login is specified in a field in the password file.
P3
Optimization|Choosing Among Shells|2-2.2|8,50
A user can choose any of the shells as the
command interpreter.
To use either the Bourne Shell or the C Shell,
issue one of the shell commands:
sh or csh
P4
Optimization|Choosing Among Shells|2-2.3|6,54
The advantage of the Bourne Shell is its brevity,
portability, ease of use, and superior speed. Thus,
sh is better for system administration scripts.
The Bourne Shell is the default shell.
P5
Optimization|Choosing Among Shells|2-2.4|10,58
The C-Shell:
* is slower that the Bourne Shell,
* offers a much better programming environment,
* has a built-in history mechanism that keeps
track of every command you type to make it
easier to recall and/or alter previous commands,
* offers an alias mechanism that allows you
to create a shorthand name for long, frequently
used commands.
P6
Optimization|Choosing Among Shells|2-2.5|16,58
The single-user mode puts the administrator root
under the Bourne shell by default. To switch to the
C-Shell enter csh.
When you invoke the C-Shell, it looks for a file
called .cshrc in you home directory and runs any
commands it finds in the file. A typical .cshrc
file might look like this:
set history=100
umask 002
alias cd 'cd \!* ; pwd'
alias h history
alias ll 'ls -la'
alias st 'cd /u3/smith/cti/startup ; pwd'
alias sp 'spell +/u3/smith/sp.list \!*'
P7
Optimization|Files and Directories that Grow|2-3.1|9,54
When using computers, probably the best surprise
is no surprise. As a system administrator, you want
to lessen the chances of clogging up your disk space
with unwanted files; therefore, you should be aware
of files and directories that grow (often unnoticed).
You'll need to know how to check the sizes
and where the culprits are most likely to be found.
P8
Optimization|Files and Directories that Grow|2-3.2|14,54
Several commands are helpful in determining
the size of files or file systems:
df, du, and ls
Remember that df tells you the file space
occupied by each file system, the amount of space
used and the space still available.
Recall also that du tells you the number of
kilobytes contained (recursively) in all files
and directories within a specified directory.
P9
Optimization|Files and Directories that Grow|2-3.3|8,54
ls -s gives you the size of the files in
a directory (in kilobytes), and will recursively
list subdirectories with the -R option. To find
the largest files in the current directory, type:
ls -s | sort -nr | more
ls -s | sort -nr | pg
To determine which files were written most
recently, use the -t (for time) option.
P10
Optimization|Files and Directories that Grow|2-3.4|12,60
Look in /usr/adm for any files that are growing
inordinately large. You can temporarily save some space
by disabling accounting and removing some accounting files.
You can also remove /usr/adm/messages.
Look for obsolete files in /tmp and /usr/tmp.
Look for obsolete files in subdirectories of /usr/spool
like /usr/spool/mail and /usr/spool/uucppublic.
P11
Optimization|Using the find Command|2-4.1|15,54
The find command locates files with particular
characteristics in specified subdirectories and can be
used to search for files in the entire file system.
Some of the file characteristics that find can
use in searching are:
* the file name,
* the file type (ordinary, directory, etc.),
* the file size in blocks,
* the file access time,
* the last time file was changed,
* the file permissions, and
* the number of links to the file, etc.
P12
Optimization|Using the find Command|2-4.2|16,54
find /a -name test -print
will look for the file test starting in the subdirectory
/a and print the file's full pathname.
find / -name core -ctime +3 -exec rm "{}" ";"
find / -name core -atime +3 -exec rm "{}" ";"
will find and delete all core files which have not
been accessed in the last 3 days.
find / -perm -4000 -a -user root -print
will find and print the names of all files for which the
set userid permissions allow a user to become root.
P13
Optimization|Reorganizing File Systems|2-5.1|11,54
UNIX uses a "first-fit block algorithm" for file
storage--all segments of memory too small to hold
required information will be passed over until the
first segment large enough is found.
On a system where hundreds of files are added and
deleted per day, the file system becomes fragmented
very quickly. Fragmentation occurs when a lot of useless
small storage locations are scattered throughout the main
memory, thereby slowing access time.
P14
Optimization|Reorganizing File Systems|2-5.2|3,54
One way to solve the fragmentation problem is to
make a new file system and restore onto it the data
that was backed up from the fragmented file system.
Optimization|Reorganizing File Systems|2-5.2|8,54
One way to solve the fragmentation problem is to
make a new file system and restore onto it the data
that was backed up from the fragmented file system.
Systems compatible with UNIX System V, Rel. 2.0
have a utility called dcopy which reorganizes a file
system for optimal access time.
Optimization|Reorganizing File Systems|2-5.2|8,54
One way to solve the fragmentation problem is to
make a new file system and restore onto it the data
that was backed up from the fragmented file system.
The tunefs utility will tune up an existing
file system by changing the dynamic parameters
of a file system which affect the layout policies.
P15
Optimization|Keeping Directories Small|2-6.1|15,54
One reason for having a hierarchical file system
is so that a user does not have to keep all files in
one directory. It helps users to organize their files.
Thus, as a system administrator, you should try
to find and discourage directories greater than 5K
(320 entries, 16 bytes/file).
The command to search for and print the pathnames
of all directory files of 5K (512 bytes/block) is:
find / -type d size +10 -print
P16
Optimization|Keeping Directories Small|2-6.2|7,58
Making a directory smaller does not reduce the size
of the directory file (or record) because empty directory
entries are available for reuse. That is, when you remove
files you just remove the physical file, not the record of
the file. You would have to remove the entire directory
and then create it again to free up the space used by the
directory file itself.
P17
Optimization|Keeping Directories Small|2-6.3|12,54
To compact a directory you must rename the directory,
and then recreate it and move files back into it. For
example, compacting /a/is directory:
mv /a/is /a/new_is
rmdir /a/is
mkdir /a/is
chmod 0755 /a/is
cd /a/new_is
find . -print | cpio -plm ../is
cd ..
rm -rf new_is
Optimization|Keeping Directories Small|2-6.3|12,62
To save space, you can compact files in a directory
with the compress utility. The syntax is: compress filename.
For example:
compress program.c
will compress the text in program.c and place the output
in a file called program.c.Z. program.c will be removed.
To list the contents of the compressed file without
altering it you can type:
zcat program.c or zcat program.c.Z
P18
Optimization|Keeping Directories Small|2-6.4|8,58
To return a compressed file to its original state, type:
decompress program.c or decompress program.c.Z
You can compress or decompress entire directories with the
* wild card. For example:
compress *
P19
Optimization|Using fsck Effectively|2-7.1|10,54
The fsck program is an interactive file system
check and repair program. It is an intelligent tool
to keep your file system healthy, and should be used
constantly during the boot process and after mounting
a file system.
fsck is normally called by the /etc/rc script
during automatic reboot when it reads the table
/etc/checklist to determine which file systems to check.
/etc/fstab to determine which file systems to check.
P20
Optimization|Using fsck Effectively|2-7.2|14,54
If a file system is consistent, the number of
files, number of blocks used, and number of free blocks
are reported. If the file system is inconsistent, the
operator is prompted before any correction is attempted.
In system tuning you may wish to use fsck with
a -S flag which conditionally reconstructs the free
a -p flag which conditionally reconstructs the free
list (the list of free inodes on a file system).
Using this option will force a no response to all fsck
questions. For a file system called /dev/rkb0, the
command would be:
fsck -S /dev/rkb0
fsck -p /dev/rkb0
P21
Optimization|Communicating with Users|2-8.1|5,54
If you are the system administrator, it is your
responsibility to inform the users that the system
is going down, the date and duration of system down
time during maintenance, that new software has been
installed on the system, etc.
P22
Optimization|Communicating with Users|2-8.2|12,58
The basic UNIX tools for performing these functions
are:
1. /etc/motd - message of the day file, the content
of which is displayed during the login time.
2. wall - (discussed in an earlier course) a write to all
command for use in emergencies or prior to system shutdown!
3. /usr/news (System V), a file where the system
administrator normally places the news items. The
news items may be displayed if so specified in the
login command files.
3. /usr/msgs, a directory where the system administrator
normally places the news items. The news items may
be displayed if so specified in the login command
files.
P23
Optimization|Using the calendar Command|2-9.1|8,54
A friendly tool under UNIX is an electronic
reminder service called calendar
Calendar service is normally started with an
entry in the /usr/lib/crontab file. This causes cron
to look for a calendar file in a user's home directory.
Any line in the file containing the current date will
be mailed to the user.