You are on page 1of 31

BrainBuzz

Cramsession

TM


Notice: While every precaution has been taken in the preparation of this material, neither the author nor BrainBuzz.com
assumes any liability in the event of loss or damage directly or indirectly caused by any inaccuracies or incompleteness of
the material contained in this document. The information in this document is provided and distributed “as-is”, without any
expressed or implied warranty. Your use of the information in this document is solely at your own risk, and Brainbuzz.com
cannot be held liable for any damages incurred through the use of this material. The use of product names in this work is
for information purposes only, and does not constitute an endorsement by, or affiliation with BrainBuzz.com. Product
names used in this work may be registered trademarks of their manufacturers. This document is protected under US and
international copyright laws and is intended for individual, personal use only. For more details, visit our legal page.
© 2000 All Rights Reserved – BrainBuzz.com
Last updated June, 2000. CIIck
here for updates.
CIIck here to see addItIonaI
documents reIated to thIs study
guIde. CIIck here to receIve free
practIce questIons for LPI
GeneraI LInux Part 2.

Contents
Contents............................... 1
LPI Exam 102........................ 3
DevIce FIIes........................... 3
LILO..................................... 4
Tar....................................... 4
InstaIIIng an AutoconfIgurIng
Package................................ 5
ManagIng Shared LIbrarIes ...... 6
dpkg .................................... 6
dseIect ................................. 7
AIIen .................................... 7
RPM ..................................... 8
What's In an RPM package
anyway? ............................... 8
ModuIes.............................. 10
BuIIdIng a KerneI ................. 11
Text edItIng (vI), ProcessIng,
PrIntIng .............................. 12
PrIntIng .............................. 13
LPD.................................... 14
LPR.................................... 14
LPQ.................................... 14
LPC.................................... 15
LPRM.................................. 15
SheIIs, ScrIptIng, ProgrammIng,
CompIIIng ........................... 16
The X DIspIay Manager ......... 21
Port AssIgnments: (onIy a partIaI IIst of
most popuIar) ..................... 22
Subnet Mask tabIe ............... 23

Cramsession" for
LPI General Linux
Part 2
Abstract:
ThIs CramsessIon wIII heIp you to
prepare for LInux Exam 102, LPI GeneraI
LInux Part 2. Exam TopIcs IncIude
Hardware & ArchItecture, LInux
InstaIIatIon and Package Management,
KerneI, Text EdItIng, ProcessIng,
PrIntIng, SheIIs, ScrIptIng, ProgrammIng,
CompIIIng, X, NetworkIng FundamentaIs,
ServIces and SecurIty.








BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

2

BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

3

LPI General Linux Part 2
LPI Exam 102

Device Files
FIrst FIoppy /dev/fd0
Second FIoppy /dev/fd1
FIrst IDE drIve /dev/hda
PartItIons
FIrst PrImary /dev/hda1
Second PrImary /dev/hda2
ThIrd PrImary /dev/hda3
Fourth PrImary /dev/hda4
FIrst LogIcaI /dev/hda5
/dev/had....
Second IDE
drIve /dev/hdb
Second IDE
PrImary /dev/hdb1

FIrst SCSI drIve /dev/sda
Second SCSI
drIve /dev/sdb
• A swap partItIon can be a prImary partItIon, or a IogIcaI partItIon, and a swap
partItIon has no restrIctIons on where It needs to be pIaced on the hard drIve.
• Swap partItIon sIze shouId be 1.5 to 2 tImes the amount of physIcaI RAM In
the computer.
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

4
LILO
In order to confIgure LILO you wIII need to edIt the fIIe/etc/IIIo.conf. The foIIowIng Is
an exampIe of a LILO confIguratIon fIIe. The LInux root partItIon Is on /dev/hda2, and
WIndows Is InstaIIed on /dev/hdb1 (on the second hard drIve).
# TeII LILO the prImary boot Ioader Is on /dev/hda
boot = /dev/hda
# The boot Image to InstaII
InstaII = /boot/boot.b
# InformatIon for bootIng LInux
Image = /vmIInuz # The kerneI Is In /vmIInuz
IabeI = IInux # ThIs Is the name you wIII see If you press "tab¨ at the LILO prompt
root = /dev/hda2 # /dev/hda2 Is the root fIIesystem
# The stanza for bootIng MS-DOS
other = /dev/hdb1 # TeII LILO about wIndows partItIon
IabeI = msdos # name when at LILO prompt Is "msdos"
tabIe = /dev/hdb # The partItIon tabIe for the second drIve
• If you chose to InstaII LILO to the MBR, LILO Is responsIbIe for eIther bootIng
LInux or any other OS.
• LILO saves a backup copy of your orIgInaI boot record In a fIIe caIIed
/boot/boot.0300 (for IDE).
Tar
• Used to pack the entIre contents of a dIrectory or dIrectorIes Into a sIngIe fIIe
caIIed a tarbaII whIch can then be backed up to tape or saved as a fIIe.
• Tar preserves the entIre dIrectory organIzatIon IncIudIng fIIe ownershIp,
permIssIons, IInks, and the dIrectory structure.
The most commonIy used tar functIons are:
c - create an archIve
x - extract fIIes from an archIve
t - IIst the contents of an archIve
AddItIonaIIy, there are commonIy used optIons:
v - verbose
f filename - use the specIfIed fIIe
z - gzIp/gunzIp

BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

5
Installing an Autoconfiguring Package
An autoconfIgurIng package usuaIIy has a fIIename IIke:´foo-1.0.tar.gz' where the
number Is a versIon number. To InstaII It, fIrst you have to unpack the package to a
dIrectory somepIace:
Use gunzIp command to uncompress the package:
% gunzIp foo-1.0.tar.gz
or
% tar -zxvf foo-1.0.tar.gz
If you used gunzIp you wIII now have to use the tar command to extract the package
archIve:
% tar xf foo-1.0.tar
Now change Into the foo dIrectory and Iook for fIIes IIke ´README' or ´INSTALL'
The README or INSTALL fIIes wIII expIaIn how to confIgure the package, but the
generaI format Is as foIIows:
% cd foo-1.0
% ./confIgure
% make
% make InstaII
% su
# make InstaII
./confIgure Invokes a sheII scrIpt that Is dIstrIbuted wIth the package that confIgures
the package for you automatIcaIIy. It wIII probe your system through a set of tests
that aIIow It to automatIcaIIy generate a ´MakefIIe' from a tempIate stored In a fIIe
caIIed ´MakefIIe.In'. To InstaII your software, you need to expIIcItIy Invoke ´make'
agaIn wIth the target ´InstaII'
PIacement of fIIes durIng InstaII:
ExecutabIes /usr/IocaI/bIn
LIbrarIes /usr/IocaI/IIb
Header fIIes /usr/IocaI/IncIude
Man pages /usr/IocaI/man/
Info fIIes /usr/IocaI/Info

If you want to InstaII the package to your home dIrectory Instead of /usr/IocaI, you
wouId use the 'prefIx´ optIon:
% confIgure --prefIx=/home/foo
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

6
Managing Shared Libraries
Most of the programs on your system wIII be compIIed to use shared IIbrarIes so each
program doesn´t have to have Its own Independent set of commonIy used functIons.
Idd Is a command that wIII Iet you IIst the shared IIbrarIes for a certaIn executabIe.
Idd /usr/bIn/X11/xterm
Programs wIII execute Id.so whIch Is the component responsIbIe for fIndIng the
shared IIbrary.
A fIIe caIIed /etc/Id.so.conf wIII contaIn a IIst of dIrectorIes that Id.so searches to fInd
the shared IIbrary fIIes. (aIthough Id.so wIII ALWAYS Iook In /usr/IIb and /IIb no
matter what /etc/Id.so.conf contaIns).
IdconfIg Is a command that wIII examIne the IIbrarIes In the dIrectorIes specIfIed, as
weII as In /etc/Id.so.conf, /usr/IIb, and /IIb In order to update the IInks and cache
where necessary.
dpkg
The generaI format of a DebIan package fIIe (.deb) Is:
packagename_packageversIon-debversIon.deb
Command FunctIon:
-I QuerIes Package
-I InstaIIs software
-I LIsts InstaIIed software (equIvaIent to rpm -qa)
-r Removes the software from the system

Command Example Function
dpkg -I package.deb InstaIIs package.deb
dpkg -I package.deb LIsts Info about package.deb (rpm -qpI)
dpkg -c package.deb LIsts aII fIIes In package.deb (rpm -qpI)
dpkg -I Shows aII InstaIIed packages
dpkg -r package-name
Removes 'package-name' from the system
(as IIsted by dpkg-I)

The prIorIty of a package IndIcates how essentIaI or necessary It Is. DebIan
GNU/LInux cIassIfIes aII packages Into four dIfferent prIorIty IeveIs:
• Required
o Packages must be InstaIIed for the system to operate correctIy and
have been InstaIIed as part of the base system.
• Important
o Important packages are found on aImost aII UNIX-IIke operatIng
systems.
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

7
• Standard
o Packages that comprIse the "standard,'' character based, DebIan
GNU/LInux system. The Standard system IncIudes a faIrIy compIete
software deveIopment envIronment and GNU Emacs.
• Optional
o OptIonaI packages comprIse a faIrIy compIete system. The OptIonaI
system IncIudes TeX and the X WIndow System.
• Extra
o Extra packages are onIy usefuI to a smaII or seIect group of peopIe, or
are InstaIIed for a specIfIc purpose. Extra packages mIght IncIude such
programs as eIectronIcs and ham radIo appIIcatIons.
o Extra packages are abbrevIated In dseIect as Xtr.
dselect
SImpIe, menu-drIven Interface whIch heIps InstaII packages. It takes you through the
package InstaIIatIon process In the order of the on-screen menu:
• Access
In thIs menu you choose the method to obtaIn and InstaII the packages.
• Update
dseIect reads the Packages database(descrIbed above) and creates a database of the
packages avaIIabIe on your system.
• Select
Choose your the package you want and press Enter. To exIt the SeIect screen after
aII of the seIectIons are compIete, press Enter. ThIs returns you to the maIn screen If
there are no probIems wIth your seIectIon. You must resoIve those probIems fIrst.
When you are satIsfIed wIth any gIven screen, press Enter.
Dependency confIIcts are quIte normaI and to be expected.
• Install
dseIect runs through the entIre 800 packages and InstaIIs the ones that are seIected.
Alien
http://kItenet.net/programs/aIIen
ThIs Is a program, whIch converts between package formats. From kItenet.net:
¨A program that converts between the rpm, dpkg,stampede slp, and slackware tgz
file formats. You can use alien to convert it to your preferred package format and
install it.
Alien should not be used to replace important system packages, like sysvinit, shared
libraries, or other things that are essential for the functioning of your system. "
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

8
RPM
The foIIowIng Is some great RPM documentatIon that was generousIy provIded by
CraIg KuIesa. For more InformatIon, refer to hIs sIte here. Thanks CraIg!
What's in an RPM package anyway?
The basIc Idea of package management Is to group the tens of thousands of InstaIIed
fIIes on your computer Into a manageabIe set of packages, whIch aIIow the
admInIstrator to easIIy InstaII and unInstaII them from the computer.
RPM, however, extends thIs notIon substantIaIIy. The bIggest advantage of an
advanced package system IIke RPM Is that each package contaIns the knowledge of
what It takes to InstaII ItseIf on your computer. It contaIns InformatIon on what the
package does, what other packages It may depend upon, what capabIIItIes the
package brIngs to your system, and where the fIIes shouId go on your computer.
Your operatIng system keeps a database of every package InstaIIed on your
computer and Its capabIIItIes and dependencIes.
Invoking RPM
Before showIng you graphIcaI "poInt-and-cIIck" tooIs for managIng packages, It's
InstructIve to Iook at the RPM command ItseIf. It's amazIngIy fIexIbIe and powerfuI!
DocumentatIon for RPM Is very thorough --the man page Is terse but a usefuI
reference. The web sItehttp://www.rpm.org/ Is a treasure-trove of HOW-TO's, and
IncIudes the exceIIent book Maximum RPM, whIch Is perhaps the quIntessentIaI
reference on RPM ItseIf. It Is mandatory readIng for anyone wantIng to buIId theIr
own RPM packages.
RPM has a faIrIy sImpIe syntax, but has many modIfyIng optIons to aIIow you to teII It
to do nearIy anythIng you want. Rather than dIscuss the features at Iength, I'II
mentIon the basIc types of operatIons It can perform and hIghIIght many handy
exampIes you can use In your own arsenaI.
Commonly-used RPM "Basic Modes"
-b = BuIId New Package
-q = Query InformatIon from InstaIIed or unInstaIIed packages
-U = InstaII/upgrade packages to the system
-F = Freshen packages exIstIng on the system
-e = UnInstaII packages from the system
-V = VerIfy the vaIIdIty of packages on the system, or an unInstaIIed package
Now Iet's Iook at ways to Invoke these modes In reaIIy cooI ways!


BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

9
Installing and Uninstalling Packages

Question RPM Command
How do I InstaII a new package, or upgrade It If
It aIready exIsts?
rpm -Uvh package.rpm
If I have a dIrectory contaInIng updated
packages, how do I upgrade only the ones
currentIy on my system?
rpm -Fvh *.rpm
How do I deIete an InstaIIed package from my
computer?
rpm -e package

Querying Info from Packages

Question RPM Command
How do I see a IIst of aII InstaIIed packages on
my computer?
rpm -qa | less
I don't know what a certaIn InstaIIed package
does. How can I get It to teII me about ItseIf?
rpm -qi package
How do I ask what fIIes were InstaIIed by a
certaIn InstaIIed package?
rpm -ql package
How do I get a-yet-unInstaIIed package to gIve
me InformatIon about ItseIf and the fIIes It
wouId InstaII on my computer?
rpm -qilp package.rpm
There's a fIIe on my computer caIIed
/usr/bIn/weIrdo. How can I fInd out whIch
InstaIIed package It beIongs to?
rpm -qf
/usr/bin/weirdo
How do I fInd out whIch package InstaIIed
/usr/bIn/weIrdo, AND how do I get InformatIon
on that package and see aII the other fIIes It
InstaIIed?
rpm -qilf
/usr/bin/weirdo


BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

10
Verifying Packages

Question RPM Command
I deIeted a few fIIes by accIdent, but I don't
know what they are. Can rpm show me whIch
fIIes In Its database are now mIssIng?
rpm -Va
I thInk I've been hacked! How do I check for
fIIes that have been modIfIed or removed In
any way?
rpm -Va
'rpm -Va' takes a Iong tIme. How do I just
verIfy that a certaIn package Is OK?
rpm -Vv package
How do I test the IntegrIty of a yet-unInstaIIed
package fIIe?
rpm -K --nopgp
package.rpm

Building Source Packages
MakIng your own RPM Is beyond the scope of thIs quIck reference(see the Maximum
RPM book for that), but It's not unusuaI to want to buIId from RPM's that onIy contaIn
source code, not bInarIes. ThIs Is especIaIIy reIevant for non-InteI archItectures IIke
PowerPC, AIpha, and Sparc whIch may not have pIatform-specIfIc RPM's avaIIabIe,
onIy the source code RPM's.

Question RPM Command
I´ve downIoaded an RPM package
contaInIng source code. How do I make a
bInary RPM out of It, and then InstaII It?
Rpm -rebuild
package.src.rpm,
then
rpm -Uvh package.rpm
Miscellaneous
Question RPM Command
How do I compress and rebuIId my computer´s
RPM database?
Rpm -rebuilddb

Modules
Module
A fIIe contaInIng aII of the code for a specIfIc drIver
depmod
Creates a dependency fIIe for moduIes whIch can be used my modprobe
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

11
You normaIIy run:
depmod -a
ThIs wIII create dependencIes for aII moduIes IIsted In/etc/conf.moduIes
insmod
Loads the moduIe Into the kerneI
lsmod
LIst aII Ioaded moduIes, as weII as theIr sIze (In unIts of4k)
rmmod
UnIoad a moduIe or IIst of moduIes from the kerneI (onIy If they are not In use at the
tIme of removaI)
rmmod -r wIII recursIveIy remove the moduIes
modprobe
WIII attempt to Ioad the specIfIed moduIe as weII as other moduIes It depends upon.
If you IIst more than one moduIe It wIII try the others onIy If the fIrst one faIIs.
modprobe -a WIII Ioad aII of the moduIes Instead of just the fIrst one
modprobe -r WIII remove specIfIed moduIes as weII as theIr dependencIes
Building a Kernel
Run eIther "make confIg¨, "make xconfIg¨(If you are runnIng x and have tcI/Tk), or
"make menuconfIg¨ (If you have the curses IIbrary)
The above menu methods wIII ask you whIch components you wIsh to have as part of
the kerneI, or avaIIabIe as moduIes.
make dep
Gathers the dependencIes for each source fIIe and IncIudes them In the varIous
makefIIes
make cIean (If you have buIIt a kerneI from thIs source before)
make zImage (thIs wIII take awhIIe)
ThIs buIIds the actuaI kerneI
You shouId now have a kerneI In /usr/src/IInux/arch/I386/boot
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

12
Text editing (vi), Processing, Printing
Input mode Screen movement:
I Insert text at cursor
ctrI-
d
scroII forward haIf a
screen
a append text after cursor
ctrI-
u
scroII back haIf a
screen
I Insert text at begInnIng of IIne
ctrI-
f move to next screen
A append text at end of IIne
ctrI-
b
move to prevIous
screen
o open IIne beIow cursor
ctrI-
I redraw screen
O open IIne above cursor
Deletion and Change: Last line mode:
dw deIete a sIngIe word :w wrIte buffer
cw change a word :q QuIt
dd deIete entIre IIne :q!
force quIt wIthout
savIng
R repIace IIne :wq
wrIte and quIt
(save)
D
deIete from cursor posItIon to
end of IIne :n next fIIe
C
change from cursor posItIon to
end of IIne :r read fIIe
x deIete a sIngIe character :e edIt fIIe
r repIace a character :f fIIe name
:set set optIons on

:set
no set optIons off
:! escape to sheII
:n go to IIne n
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

13

Cursor movement: Miscellaneous
I move rIght u undo Iast actIon
h move Ieft / search forward
j move down ? search back
k move up n repeat search
$ move to end of IIne .
repeat Iast
command
^ move to begInnIng of IIne yy yank IIne
w move to next word p put beIow cursor
e move to end of word P put above cursor
1G move to fIrst IIne ZZ wrIte and quIt
nG
move to IIne n (where n Is a
number)

G move to Iast IIne

Printing
To add a prInt queue to Ipd, you must add an entry In/etc/prIntcap, and make the
new spooI dIrectory under /var/spooI/Ipd.
An entry In /etc/prIntcap Iooks IIke:
# LOCAL djet500
Ip|dj|deskjet:\
:sd=/var/spooI/Ipd/dj:\
:mx#0:\
:Ip=/dev/Ip0:\
:sh:
ThIs above prIntcap defInes a spooI caIIed Ip, dj, or deskjet, spooIed In the dIrectory
/var/spooI/Ipd/dj, wIth no per-job maxImum sIze IImIt, whIch prInts to the devIce
/dev/Ip0, and whIch does not have a banner page (wIth the name of the person who
prInted, etc) added to the front of the prInt job.
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

14
LPD
Lpd Is the IIne prInter daemon (spooI area handIer) and Is normaIIy Invoked at boot
tIme from the arc(8) fIIe. It makes a sIngIe pass through the prIntcap(5) fIIe to fInd
out about the exIstIng prInters and prInts any fIIes Ieft after a crash. It then uses the
system caIIs IIsten(2) and accept(2) to receIve requests to prInt fIIes In the queue,
transfer fIIes to the spooIIng area, dIspIay the queue, or remove jobs from the queue.
In each case, It forks a chIId to handIe the request so the parent can contInue to
IIsten for more requests.
LPR
Lpr uses a spooIIng daemon to prInt the named fIIes when facIIItIes become avaIIabIe.
If no names appear, the standard Input Is assumed.
-l
Use a fIIter whIch aIIows controI characters to be prInted and suppresses page
breaks.
-P
Force output to a specIfIc prInter. NormaIIy, the defauIt prInter Is used (sIte
dependent), or the vaIue of the envIronment varIabIe PRINTER Is used.
-h
Suppress the prIntIng of the burst page.
-m
Send maII upon compIetIon.
-r
Remove the fIIe upon compIetIon of spooIIng or upon compIetIon of prIntIng (wIth the
-s optIon).
-#num
The quantIty num Is the number of copIes desIred of each fIIe named.
LPQ
Reports the status of the specIfIed jobs or aII jobs assocIated wIth a user. Lpq,
Invoked wIthout any arguments, reports on any jobs currentIy In the queue.
OptIons:
-P
SpecIfy a partIcuIar prInter, otherwIse the defauIt IIne prInter Is used (or the vaIue of
the PRINTER varIabIe In the envIronment). AII other arguments suppIIed are
Interpreted as user names or job numbers to fIIter out onIy those jobs of Interest.
If Ipq warns that there Is no daemon present (I.e., due to some maIfunctIon), the Ipc
command can be used to restart the prInter daemon.
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

15
LPC
Used by the system admInIstrator to controI the operatIon of the IIne prInter system.
For each IIne prInter confIgured In /etc/prIntcap, Ipc maybe used to:
• DIsabIe or enabIe a prInter
• DIsabIe or enabIe a prInter's spooIIng queue
• Rearrange the order of jobs In a spooIIng queue
• fInd the status of prInters, and theIr assocIated spooIIng queues and prInter
daemons.
o WIthout any arguments, Ipc wIII prompt for commands from the
standard Input
o If arguments are suppIIed, Ipc Interprets the fIrst argument as a
command and the remaInIng arguments as parameters to the
command
o The standard Input may be redIrected causIng Ipc to read commands
from fIIe.
LPRM
• Iprm wIII remove a job, or jobs, from a prInter's spooI queue.
• usIngIprm Is normaIIy the onIy method by whIch a user may remove a job.
OptIons and arguments:
-PprInter
SpecIfy the queue assocIated wIth a specIfIc prInter (otherwIse the defauIt prInter Is
used)
-
If a sIngIe ´-' Is gIven, Iprm wIII remove aII jobs whIch a user owns. (note: If root
empIoys thIs fIag, the spooI queue wIII be emptIed entIreIy)
user
Causes Iprm to attempt to remove any jobs queued beIongIng to that user
job #
AIIows a user to remove a job from the queue by job #
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

16
Some Important Files Used in Printing
/etc/printcap
prInter descrIptIon fIIe
/var/spool/*
spooI dIrectorIes /var/spooI/*/mInfree mInImum free space toIeave
/dev/lp*
IIne prInter devIces
/dev/printer
socket for IocaI requests
/etc/hosts.equiv
IIsts machIne names aIIowed prInter access
/etc/hosts.lpd
IIsts machIne names aIIowed prInter access, but not under same
admInIstratIve controI.
/etc/passwd
personaI IdentIfIcatIon.
/etc/printcap
prInter capabIIItIes data base.
/usr/sbin/lpd*
IIne prInter daemons.
/var/spool/output/*
dIrectorIes used for spooIIng.
Shells, Scripting, Programming, Compiling
Bash Shell
/bIn/bash
The bash executabIe
/etc/profIIe
The system wIde InItIaIIzatIon fIIe, executed automatIcaIIy at login
~/.bash_profIIe
The personaI InItIaIIzatIon fIIe, executed automatIcaIIy at login
~/.bashrc
The IndIvIduaI sheII startup fIIe, executed automatIcaIIy at shell startup
~/.bash_Iogout
The IndIvIduaI Iogout fIIe, executed automatIcaIIy at logout
~/bash_hIstory
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

17
Records sessIon commands
~/.Inputrc
IndIvIduaI readIIne InItIaIIzatIon fIIe
csh and tcsh Shell
~/.cshrc
Executed automatIcaIIy at sheII startup.
~/.IogIn
Executed automatIcaIIy at IogIn after .cshrc has been processed
~/.Iogout
Executed automatIcaIIy at sheII Iogout.
Creating Shell Scripts
Note: The foIIowIng sheII programmIng documentatIon Is from an exceIIent intro by
Andrew Arensburger and has been prInted wIth hIs permIssIon. Thanks Andrew!
The fIrst IIne of any scrIpt must begIn wIth #!, foIIowed by the name of the
Interpreter.
Some versIons of UnIx aIIow whIte space between #! and the name of the
Interpreter. Others don't. Hence, If you want your scrIpt to be portabIe, Ieave out the
bIank.
A scrIpt, IIke any fIIe that can be run as a command, needs to be executabIe: save
thIs scrIpt as rotate Iog and run
chmod +x rotate Iog
to make It executabIe. You can now run It by runnIng
./rotateIog
Environment commands
set - shows aII varIabIes (IocaI and exported)
env - shows onIy exported varIabIes
export - shows exported varIabIes
unset - used to remove varIabIes
Variables
sh aIIows you to have varIabIes, just IIke any programmIng Ianguages. VarIabIes do
not need to be decIared. To set a sh varIabIe, use
VAR=vaIue
and to use the vaIue of the varIabIe Iater, use
$VAR
or
${VAR}
The Iatter syntax Is usefuI If the varIabIe name Is ImmedIateIy foIIowed by other text:
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

18
#!/bIn/sh
COLOR=yeIIow
echo ThIs Iooks $COLORIsh
echo ThIs seems ${COLOR}Ish
prInts
ThIs Iooks
ThIs seems yeIIowIsh
Variable Substitution
${VAR:-expressIon}
Use defauIt vaIue: If VAR Is set and non-nuII, expands to $VAR. OtherwIse, expands
to expressIon.
${VAR:=expressIon}
Set defauIt vaIue: If VAR Is set and non-nuII, expands to $VAR. OtherwIse, sets VAR
to expressIon and expands to expressIon.
${VAR:?[expressIon]}
If VAR Is set and non-nuII, expands to $VAR. OtherwIse, prInts expressIon to
standard error and exIts wIth a non-zero exIt status.
${VAR:+expressIon}
If VAR Is set and non-nuII, expands to the empty strIng. OtherwIse, expands to
expressIon.
${#VAR}
Expands to the Iength of $VAR.
Flow control
sh supports severaI fIow-controI constructs, whIch add power and fIexIbIIIty to your
scrIpts.
if
The If statement Is a sImpIe condItIonaI. You've seen It In every programmIng
Ianguage. Its syntax Is
If condItIon ; then
commands
[eIIf condItIon ; then
commands]...
[eIse
commands]
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

19
fi
That Is, an If-bIock, optIonaIIy foIIowed by one or more eIIf-bIocks (eIIf Is short for
´´eIse If''), optIonaIIy foIIowed by aneIse-bIock, and termInated by fI.
The If statement pretty much does what you'd expect: If condItIon Is true, It executes
the If-bIock. OtherwIse, It executes the eIse-bIock, If there Is one. The eIIf construct
Is just syntactIc sugar, to Iet you avoId nestIng muItIpIe If statements.
#!/bIn/sh
myname=´whoamI´
If [ $myname = root ]; then
echo "WeIcome to FooSoft 3.0"
eIse
echo "You must be root to run thIs scrIpt"
exIt 1
fI
The more observant among you (or those who are math majors) are thInkIng,
´´Hey! You forgot to IncIude the square brackets In the syntax defInItIon!''
ActuaIIy, I dIdn't: [ Is actuaIIy a command, /bIn/[, and Is another name for the test
command. ThIs Is why you shouIdn't caII a test program test: If you have ´´.'' at the
end of your path, as you shouId, executIng test wIII run /bIn/test.
The condItIon can actuaIIy be any command. If It returns a zero exIt status, the
condItIon Is true; otherwIse, It Is faIse. Thus, you can wrIte thIngs IIke
#!/bIn/sh
user=arnIe
If grep $user /etc/passwd; then
echo "$user has an account"
eIse
echo "$user doesn't have an account"
fI
while
The whIIe statement shouId aIso be famIIIar to you from any number of other
programmIng Ianguages. Its syntax In sh Is
whIIe condItIon; do
commands
done
As you mIght expect, the whIIe Ioop executes commands as Iong as condItIon Is true.
AgaIn, condItIon can be any command, and Is true If the command exIts wIth a zero
exIt status.
A whIIe Ioop may contaIn two specIaI commands: break and contInue.
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

20
break exIts the whIIe Ioop ImmedIateIy, jumpIng to the next statement after the
done.
contInue skIps the rest of the body of the Ioop, and jumps back to the top, to where
condItIon Is evaIuated.
for
for var In IIst; do The for Ioop Iterates over aII of the eIements In a IIst. Its syntax Is

commands
done
IIst Is zero or more words. The for construct wIII assIgn the varIabIe var to each word
In turn, then execute commands. For exampIe:
#!/bIn/sh
for I In foo bar baz "do be do"; do
echo "$I"
done
wIII prInt
foo
bar
baz
do be do
A for Ioop may aIso contaIn break and contInue statements. They work the same way
as In the whIIe Ioop.
case
The case construct works IIke C's swItch statement, except that It matches patterns
Instead of numerIcaI vaIues. Its syntax Is
case expressIon In
pattern)
commands
;;
...
esac
expressIon Is a strIng; thIs Is generaIIy eIther a varIabIe or aback quoted command.
pattern Is a gIob pattern (see gIobbIng).
The patterns are evaIuated In the order In whIch they are seen, and onIy the fIrst
pattern that matches wIII be executed. Often, you'II want to IncIude a ´´none of the
above'' cIause; to do thIs, use * as your Iast pattern.
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

21
The X Display Manager
xdm

can be confIgured wIth confIguratIon fIIes Iocated In/usr/X11R6/IIb/X11/xdm on your
LInux system.
xdm-config
FIIe whIch confIgures how the IogIn screen appears to users, andXsetup_0 Is used to
teII xdm what programs shouId be Iaunched when X Is started.
Every X Server has a dIspIay name of the form:
• hostname:dIspIaynumber.screennumber
hostname
SpecIfIes the name of the machIne to whIch the dIspIay Is actuaIIy,
physIcaIIy connected (If host Isn´t specIfIed IocaI host Is used)
DIspIay number
used If the X Server Is controIIIng more than one keyboard and
monItor unIt, for Instance, a network of X termInaIs.
Screen number
specIfIes whIch monItor In a muItIpIe monItor setup shouId be used
XF86Setup
• provIded by the Xfree86 team
• starts a VGA X server wIth 16 coIors whIch aIIows you to then seIect your
vIdeo card, monItor, and mouse types
Config XF86
• Text based setup program whIch wIII generate a confIg fIIe from your answers
• Good to use If XF86Setup can´t be run for some reason
Xconfigurator
• ProvIded by RedHat
.XdefauIts
Can contaIn every optIon you prefer for every type of program you run In X
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

22
Troubleshooting X
x -showconIfg
DIspIays the chIpset names known to your X server
x -probeonIy
Have the X server probe your chIpset for you
StartIng X
startx actuaIIy caIIs xInIt whIch Is the program responsIbIe for statIng the X server
and cIIents
Port Assignments: (only a partial list of most popular)
Keyword DecImaI DescrIptIon
chargen 19/tcp Character Generator
chargen 19/udp Character Generator
ftp-data 20/tcp FIIe Transfer [DefauIt Data]
ftp-data 20/udp FIIe Transfer [DefauIt Data]
ftp 21/tcp FIIe Transfer [ControI]
ftp 21/udp FIIe Transfer [ControI]
ssh 22/tcp SSH Remote LogIn ProtocoI
ssh 22/udp SSH Remote LogIn ProtocoI
teInet 23/tcp TeInet
teInet 23/udp TeInet
domaIn 53/tcp DomaIn Name Server
domaIn 53/udp DomaIn Name Server
bootps 67/tcp Bootstrap ProtocoI Server
bootps 67/udp Bootstrap ProtocoI Server
bootpc 68/tcp Bootstrap ProtocoI CIIent
bootpc 68/udp Bootstrap ProtocoI CIIent
tftp 69/tcp TrIvIaI FIIe Transfer
tftp 69/udp TrIvIaI FIIe Transfer
gopher 70/tcp Gopher
gopher 70/udp Gopher
fInger 79/tcp FInger
fInger 79/udp FInger
http 80/tcp WorId WIde Web HTTP
http 80/udp WorId WIde Web HTTP
kerberos 88/tcp Kerberos
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

23
kerberos 88/udp Kerberos
rteInet 107/tcp Remote TeInet ServIce
rteInet 107/udp Remote TeInet ServIce
pop3 110/tcp Post OffIce ProtocoI - VersIon 3
pop3 110/udp Post OffIce ProtocoI - VersIon 3
sunrpc 111/tcp SUN Remote Procedure CaII
sunrpc 111/udp SUN Remote Procedure CaII
Ident 113/tcp
auth 113/tcp AuthentIcatIon ServIce
auth 113/udp AuthentIcatIon ServIce
nntp 119/tcp Network News Transfer ProtocoI
nntp 119/udp Network News Transfer ProtocoI
Imap 143/tcp Internet Message Access ProtocoI
Imap 143/udp Internet Message Access ProtocoI
snmp 161/tcp SNMP
snmp 161/udp SNMP
snmptrap 162/tcp SNMPTRAP
snmptrap 162/udp SNMPTRAP
Subnet Mask table
# of
BIts
Dotted DecImaI HexadecImaI # of
Hosts
16 255.255.0.0 FF-FF-00-00 65534
17 255.255.128.0 FF-F8-00-00 32766
18 255.255.192.0 FF-FF-C0-00 16382
19 255.255.224.0 FF-FF-E0-00 8190
20 255.255.240.0 FF-FF-F0-00 4094
21 255.255.248.0 FF-FF-F8-00 2046
22 255.255.252.0 FF-FF-FC-00 1022
23 255.255.254.0 FF-FF-FE-00 510
24 255.255.255.0 FF-FF-FF-00 254
25 255.255.255.128 FF-FF-FF-80 126
26 255.255.255.192 FF-FF-FF-C0 62
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

24
27 255.255.255.224 FF-FF-FF-E0 30
28 255.255.255.240 FF-FF-FF-F0 14
29 255.255.255.248 FF-FF-FF-F8 6
30 255.255.255.252 FF-FF-FF-FC 2

ifconfig command

up
thIs optIon actIvates an Interface (and Is the defauIt).
down
thIs optIon deactIvates an Interface.
[-]arp
thIs optIon enabIes or dIsabIes use of the address resoIutIon protocoI on thIs Interface
netmask <addr>
thIs parameter aIIows you to set the network mask of the network thIs devIce
beIongs to.
Networking Configuration Files
/etc/resolv.conf
MaIn confIguratIon fIIe for name resoIutIon. There are three keywords typIcaIIy used.
They are:
domain
thIs keyword specIfIes the IocaI domaIn name
search
thIs keyword specIfIes a IIst of aIternate domaIn names to search for a
hostname
nameserver
You can IIst eIther a sIngIe name server or muItIpIe name servers
• An exampIe /etc/resoIv.conf mIght Iook somethIng IIke:
domaIn somecoIIege.edu.ca
search scIence.somecoIIege.edu.au
nameserver 192.168.1.200
nameserver 192.168.1.201
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

25
/etc/host.conf
Governs the order In whIch to resoIve names. For exampIe the foIIowIng host. conf
fIIe wouId check the hosts fIIe fIrst and then query dns.The "muItI on¨ entry aIIows
you to have muItIpIe IP addresses for your machIne.
order hosts,bInd
muItI on
/etc/hosts
ContaIns host name to IP address mappIngs. If you confIgure some entrIes In the
hosts fIIe and you have the order of your host.conf fIIe checkIng hosts fIrst, you wIII
try to resoIve any hostnames by checkIng the hosts fIIe fIrst and If the entry Is not
found you wIII then resort to queryIng a dns server.
# /etc/hosts
127.0.0.1 IocaIhost I
www.somedomaIn.com
/etc/networks
AIIows you to refer to dotted decImaI IP´s by a name rather than IP. ThIs Is handy
when you are usIng the route command because you can refer to networks such as
"IocaInet¨ Instead of 192.168.1.0.
/etc/services
The /etc/servIces fIIe Is a sImpIe database that assocIates a human frIendIy name to
a machIne frIendIy servIce port. Each entry Is comprIsed of three fIeIds separated by
any number of whIte space (tab or space) characters. The fIeIds are:
name port/protocoI aIIases # comment
name
a sIngIe word name that represents the servIce beIng descrIbed.
port/protocol
thIs fIeId Is spIIt Into two subfIeIds.
port
a number that specIfIes the port number the named servIce wIII be avaIIabIe
on. Most of the common servIces have assIgned servIce numbers. These are
descrIbed In RFC-1340.
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

26
protocol
may be set to eIther tcp or udp. It Is Important to note that an entry of 18/tcp
Is very dIfferent from an entry of 18/udp and that there Is no technIcaI reason
why the same servIce needs to exIst on both. NormaIIy commonsense prevaIIs
and It Is onIy If a partIcuIar servIce Is avaIIabIe vIa both tcp and udp that you
wIII see an entry for both.
aliases
other names that may be used to refer to thIs servIce entry.
Networking Services
/etc/inetd.conf
ResponsIbIe for startIng servIces, typIcaIIy ones that do not need to run contInuousIy,
or are sessIon based (such as teInet, or ftpd).
Whenever you make changes to Inetd.conf you must restart Inetd to make the
changes effectIve.
ps -aux|grep Inetd
(now note the process number)
kIII -HUP <process Id of Inetd>
LInes In Inetd.conf can be commented out wIth a #
Access to programs started by Inetd can be easIIy controIIed by the use of
TCP_WRAPPERS.
TCP_WRAPPERS
TCP_WRAPPERS Is controIIed from two fIIes:
/etc/hosts.aIIow
/etc/hosts.deny
hosts.aIIow Is checked fIrst, and the ruIes are checked from fIrst to Iast. If It faIIs to
fInd a ruIe denyIng you entry It then by defauIt Iets you. A good Idea Is to make the
Iast ruIe In your /etc/hosts.deny as foIIows:
ALL: 0.0.0.0/0.0.0.0
ThIs means aII servIces, aII IocatIons, so any servIce not expIIcItIy aIIowed Is then
bIocked (don´t forget that the defauIt Is to aIIow).
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

27
Sendmail
You can use sendmaII from eIther the command IIne, or through a front end maII
reader.
SendmaII uses three MAIN confIguratIon fIIes: (there are many more)
Sendmail.cw
ThIs fIIe Is used to store the names of hosts whIch wIII receIve emaII
Sendmail.cf
ThIs Is a very compIex confIguratIon fIIe for SendmaII.
*.mc
ThIs Is used to heIp the admInIstrator confIgure sendmaII so hopefuIIy you
won´t have to create your own sendmaII.cf
Apache
BasIc confIguratIon fIIes:
httpd.conf
ContaIns entIre server processIng reIated commands.
arm.conf
ContaIns server resource InformatIon
access.conf
Per dIrectory confIguratIon
AII of these fIIes are found In /etc/httpd/apache/conf or/etc/httpd/conf
httpd
-C "dIrectIve¨ Process dIrectIve BEFORE readIng confIg fIIes
-c "dIrectIve¨ Process dIrectIve AFTER readIng confIguratIon fIIes
-d dIrectory AIternate server root dIrectory
-f fIIe ConfIg fIIe
-I LIst compIIe In moduIes
The DNS Database Files
In order to get DNS runnIng you are goIng to need entrIes In some text fIIes that wIII
map the host names to Ip addresses and vIce versa. These fIIes are typIcaIIy referred
to as db fIIes and contaIn your resource records. Most peopIe wIII name theIr fIIes
db.yourdomaIn (whIch wouId hoId aII entrIes for yourdomaIn.com), and db.192.168.1
for your reverse Iookup zone. The other db fIIes you mIght need are: db.cache and
db.127.0.0. The db.cache fIIe teIIs your server where the servers for the ".¨ (root)
domaIn are Iocated so you can resoIve querIes for whIch you are not authorItatIve.
Thedb.127.0.0 entry Is for your Ioopback address. You wIII aIso need a boot fIIewhIch
wIII contaIn the InformatIon on where each of your confIguratIon fIIes are Iocated.
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

28
ThIs fIIe wIII basIcaIIy tIe aII of the db fIIes together. Here Is asampIe /etc/named.conf
fIIe:
DIrectory "/var/named¨
Zone ".¨ {
Type hInt
FIIe "db.cache¨;
};
zone "yourdomaIn.com¨ {
type master;
fIIe "db.yourdomaIn.com¨;
};
zone "1.168.192.In-addr.arpa¨ {
type master;
fIIe "db.192.168.1¨;
};
zone "0.0.127.In-addr.arpa¨ {
type master;
fIIe "db.127.0.0¨´
};
Resource record representatIons In master fIIes share a common format, whIch Is
[domaIn] [ttI] [cIass] type rdata
FIeIds are separated by spaces or tabs. An entry may be contInued across severaI
IInes If an openIng brace occurs before the fIrst newIIne, and the Iast fIeId Is foIIowed
by a cIosIng brace. AnythIng between a semIcoIon and a newIIne Is Ignored.
domain
ThIs Is the domaIn name to whIch the entry appIIes. If no domaIn name Is gIven, the
RR Is assumed to appIy to the domaIn of the prevIous RR.
SOA
The Start Of AuthorIty record sIgnaIs that the records foIIowIng the SOA RR contaIn
authorItatIve InformatIon for the domaIn.
serial
ThIs Is the versIon number of the zone fIIe, expressed as a sIngIe decImaI number.
Whenever data Is changed In the zone fIIe, thIs number shouId be Incremented. ThIs
Is how secondary name servers are aware of changes to the zone.

refresh
IntervaI for how often the secondary shouId check wIth the prImary nameserver for
zone changes
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

29
retry
DetermInes the IntervaI durIng whIch a secondary server shouId retry contactIng the
prImary server If a request or a zone refresh faIIs
expire
SpecIfIes when a secondary name server shouId dIscard Its copy of the zone
database because the prImary nameserver couId not be contacted. ThIs Is to ensure
the copy of the zone database does not contaIn InvaIId data.

minimum
ThIs Is the defauIt ttI vaIue for resource records that do not expIIcItIy specIfy one.
Other name servers shouId dIscard the RR after thIs tIme
A
ThIs assocIates an IP address wIth a hostname. Each host shouId onIy have one A
record. AII other hostnames are aIIases and must be mapped onto the canonIcaI
hostname usIng a CNAME record
NS
ThIs poInts to a master name server of a subordInate zone
CNAME
ThIs assocIates an aIIas for a host wIth Its canonIcaI hostname. The canonIcaI
hostname Is the one the master fIIe provIdes an A record for; aIIases are sImpIy
IInked to that name by a CNAME record, but don't have any other records of theIr
own.
PTR
Used to assocIate names In the In- addr.arpa domaIn wIth hostnames. ThIs Is used In
the reverse Iookup zone where you are mappIng IP addresses to hostnames
(normaIIy you map hostnames TO addresses)

MX
ThIs RR announces a maII exchanger for a domaIn. The syntax ofan MX record Is
[domaIn] [ttI] [cIass] MX preference host

HINFO
ProvIdes InformatIon on the system's hardware and software. Its syntax Is
[domaIn] [ttI] [cIass] HINFO hardware software
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

30
NFS
Setup:
The client:
mount -t nfs server.whatever.edu:/export ./your_mnt_poInt
You can automate these mounts by pIacIng a IIne In our/etc/fstab fIIe whIch wIII
provIde us a IIst of the devIces to mount (both IocaI and network) at boot tIme.
nfsserver:/usr/IocaI /usr/IocaI nfs noIock 0 0
AIso, make sure you are runnIng the RPC portmapper. (rpcInfo-p)
The server:
In addItIon to the portmap program (whIch Is requIred by both the cIIent and server)
you wIII aIso requIre rpc.mountd and rpc.nfsd to be runnIng. These daemons wIII Iook
at a fIIe caIIed /etc/exports to Iocate what dIrectorIes to export vIa NFS. A sImpIe
/etc/exports fIIe wouId Iook IIke:
/FooBarDIr
The /etc/exports fIIe offers more optIons whIch can be Iocated In man exports. A
more InvoIved /etc/exports fIIe mIght Iook IIke:
/home *.domaIn.sIte.edu(rw)
/prIvate (noaccess)
/usr/IocaI *.domaIn.sIte.edu(ro)
At thIs poInt we Iaunch portmap, rpc.mountd, rpc.nfsd and check now wIth our
/usr/sbIn/exportfs and /usr/sbIn/showmount. If workIng correctIy we now have
exported fIIesystems whIch our NFS cIIent machInes can access.
SAMBA
The /etc/smb.conf fIIe Iets you specIfy a varIety of optIons that controI Samba's
operatIon. The InstaII scrIpt for Samba estabIIshes a sImpIe /etc/sbm.conf that may
meet your requIrements.
Samba IncIudes a tooI caIIed swat that Iets you vIew and change optIons by usIng
your Web browser, whIch Is generaIIy much easIer than usIng a text edItor.
The swat tooI verIfIes the vaIues of parameters you enter and provIdes onIIne heIp.
To access swat, poInt your browser to port 901 of your system.
To confIgure your Samba server from SWAT, you cIIck on sImuIated tooI bar entrIes:
Globals Iets you confIgure gIobaI Samba varIabIes(optIons)
Shares Iets you confIgure fIIe shares
Printers Iets you confIgure shared prInters
Status Iets you vIew the status of the Samba server
View Iets you vIew the smb.conf fIIe
Password Iets you add and deIete users and change user passwords
Daemons needed for runnIng Samba:
smbd (The SMB daemon)
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

31
nmbd
The nmbd program Is Samba's NetBIOS name and browsIng daemon
Samba Commands:
Smbclient
Used to communIcate wIth SMB Servers
smbclient //server_name/share_name [password][-options]
Testparm
checks an smb.conf fIIe for obvIous errors and seIf-consIstency
testparm [options] configfile_name [hostname IP_addr]
Testprns
checks a specIfIed prInter name agaInst the system prInter capabIIItIes
(prIntcap) fIIe. Its command IIne Is:
testprns printername [printcapname]
Smbstatus
IIsts the current connectIons on a Samba server