You are on page 1of 31




Notice: While every precaution has been taken in the preparation of this material, neither the author nor
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
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 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 –
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............................... 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
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


BraInBuzz CramsessIon: LPI GeneraI LInux Part 2


LPI General Linux Part 2
LPI Exam 102

Device Files
FIrst FIoppy /dev/fd0
Second FIoppy /dev/fd1
FIrst IDE drIve /dev/hda
FIrst PrImary /dev/hda1
Second PrImary /dev/hda2
ThIrd PrImary /dev/hda3
Fourth PrImary /dev/hda4
FIrst LogIcaI /dev/hda5
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

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

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
% tar -zxvf foo-1.0.tar.gz
If you used gunzIp you wIII now have to use the tar command to extract the package
% 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

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 whIch Is the component responsIbIe for fIndIng the
shared IIbrary.
A fIIe caIIed /etc/ wIII contaIn a IIst of dIrectorIes that searches to fInd
the shared IIbrary fIIes. (aIthough wIII ALWAYS Iook In /usr/IIb and /IIb no
matter what /etc/ contaIns).
IdconfIg Is a command that wIII examIne the IIbrarIes In the dIrectorIes specIfIed, as
weII as In /etc/, /usr/IIb, and /IIb In order to update the IInks and cache
where necessary.
The generaI format of a DebIan package fIIe (.deb) Is:
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
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

• 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.
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.
ThIs Is a program, whIch converts between package formats. From
¨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

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

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
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
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
rpm -qilf

BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

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

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
rpm -Uvh package.rpm
Question RPM Command
How do I compress and rebuIId my computer´s
RPM database?
Rpm -rebuilddb

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

You normaIIy run:
depmod -a
ThIs wIII create dependencIes for aII moduIes IIsted In/etc/conf.moduIes
Loads the moduIe Into the kerneI
LIst aII Ioaded moduIes, as weII as theIr sIze (In unIts of4k)
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
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
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

Text editing (vi), Processing, Printing
Input mode Screen movement:
I Insert text at cursor
scroII forward haIf a
a append text after cursor
scroII back haIf a
I Insert text at begInnIng of IIne
f move to next screen
A append text at end of IIne
move to prevIous
o open IIne beIow cursor
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
R repIace IIne :wq
wrIte and quIt
deIete from cursor posItIon to
end of IIne :n next fIIe
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

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


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
^ 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
move to IIne n (where n Is a

G move to Iast IIne

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

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 uses a spooIIng daemon to prInt the named fIIes when facIIItIes become avaIIabIe.
If no names appear, the standard Input Is assumed.
Use a fIIter whIch aIIows controI characters to be prInted and suppresses page
Force output to a specIfIc prInter. NormaIIy, the defauIt prInter Is used (sIte
dependent), or the vaIue of the envIronment varIabIe PRINTER Is used.
Suppress the prIntIng of the burst page.
Send maII upon compIetIon.
Remove the fIIe upon compIetIon of spooIIng or upon compIetIon of prIntIng (wIth the
-s optIon).
The quantIty num Is the number of copIes desIred of each fIIe named.
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.
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

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
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
o The standard Input may be redIrected causIng Ipc to read commands
from fIIe.
• 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:
SpecIfy the queue assocIated wIth a specIfIc prInter (otherwIse the defauIt prInter Is
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)
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

Some Important Files Used in Printing
prInter descrIptIon fIIe
spooI dIrectorIes /var/spooI/*/mInfree mInImum free space toIeave
IIne prInter devIces
socket for IocaI requests
IIsts machIne names aIIowed prInter access
IIsts machIne names aIIowed prInter access, but not under same
admInIstratIve controI.
personaI IdentIfIcatIon.
prInter capabIIItIes data base.
IIne prInter daemons.
dIrectorIes used for spooIIng.
Shells, Scripting, Programming, Compiling
Bash Shell
The bash executabIe
The system wIde InItIaIIzatIon fIIe, executed automatIcaIIy at login
The personaI InItIaIIzatIon fIIe, executed automatIcaIIy at login
The IndIvIduaI sheII startup fIIe, executed automatIcaIIy at shell startup
The IndIvIduaI Iogout fIIe, executed automatIcaIIy at logout
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

Records sessIon commands
IndIvIduaI readIIne InItIaIIzatIon fIIe
csh and tcsh Shell
Executed automatIcaIIy at sheII startup.
Executed automatIcaIIy at IogIn after .cshrc has been processed
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
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
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
Environment commands
set - shows aII varIabIes (IocaI and exported)
env - shows onIy exported varIabIes
export - shows exported varIabIes
unset - used to remove varIabIes
sh aIIows you to have varIabIes, just IIke any programmIng Ianguages. VarIabIes do
not need to be decIared. To set a sh varIabIe, use
and to use the vaIue of the varIabIe Iater, use
The Iatter syntax Is usefuI If the varIabIe name Is ImmedIateIy foIIowed by other text:
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

echo ThIs Iooks $COLORIsh
echo ThIs seems ${COLOR}Ish
ThIs Iooks
ThIs seems yeIIowIsh
Variable Substitution
Use defauIt vaIue: If VAR Is set and non-nuII, expands to $VAR. OtherwIse, expands
to expressIon.
Set defauIt vaIue: If VAR Is set and non-nuII, expands to $VAR. OtherwIse, sets VAR
to expressIon and expands to 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.
If VAR Is set and non-nuII, expands to the empty strIng. OtherwIse, expands to
Expands to the Iength of $VAR.
Flow control
sh supports severaI fIow-controI constructs, whIch add power and fIexIbIIIty to your
The If statement Is a sImpIe condItIonaI. You've seen It In every programmIng
Ianguage. Its syntax Is
If condItIon ; then
[eIIf condItIon ; then
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

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.
If [ $myname = root ]; then
echo "WeIcome to FooSoft 3.0"
echo "You must be root to run thIs scrIpt"
exIt 1
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
If grep $user /etc/passwd; then
echo "$user has an account"
echo "$user doesn't have an account"
The whIIe statement shouId aIso be famIIIar to you from any number of other
programmIng Ianguages. Its syntax In sh Is
whIIe condItIon; do
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

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

IIst Is zero or more words. The for construct wIII assIgn the varIabIe var to each word
In turn, then execute commands. For exampIe:
for I In foo bar baz "do be do"; do
echo "$I"
wIII prInt
do be do
A for Ioop may aIso contaIn break and contInue statements. They work the same way
as In the whIIe Ioop.
The case construct works IIke C's swItch statement, except that It matches patterns
Instead of numerIcaI vaIues. Its syntax Is
case expressIon In
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

The X Display Manager

can be confIgured wIth confIguratIon fIIes Iocated In/usr/X11R6/IIb/X11/xdm on your
LInux system.
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
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
• 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
• ProvIded by RedHat
Can contaIn every optIon you prefer for every type of program you run In X
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

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

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
Dotted DecImaI HexadecImaI # of
16 FF-FF-00-00 65534
17 FF-F8-00-00 32766
18 FF-FF-C0-00 16382
19 FF-FF-E0-00 8190
20 FF-FF-F0-00 4094
21 FF-FF-F8-00 2046
22 FF-FF-FC-00 1022
23 FF-FF-FE-00 510
24 FF-FF-FF-00 254
25 FF-FF-FF-80 126
26 FF-FF-FF-C0 62
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

27 FF-FF-FF-E0 30
28 FF-FF-FF-F0 14
29 FF-FF-FF-F8 6
30 FF-FF-FF-FC 2

ifconfig command

thIs optIon actIvates an Interface (and Is the defauIt).
thIs optIon deactIvates an Interface.
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
MaIn confIguratIon fIIe for name resoIutIon. There are three keywords typIcaIIy used.
They are:
thIs keyword specIfIes the IocaI domaIn name
thIs keyword specIfIes a IIst of aIternate domaIn names to search for a
You can IIst eIther a sIngIe name server or muItIpIe name servers
• An exampIe /etc/resoIv.conf mIght Iook somethIng IIke:
BraInBuzz CramsessIon: LPI GeneraI LInux Part 2

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
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 IocaIhost I
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
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
a sIngIe word name that represents the servIce beIng descrIbed.
thIs fIeId Is spIIt Into two subfIeIds.
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

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.
other names that may be used to refer to thIs servIce entry.
Networking Services
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 Is controIIed from two fIIes:
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:
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

You can use sendmaII from eIther the command IIne, or through a front end maII
SendmaII uses three MAIN confIguratIon fIIes: (there are many more)
ThIs fIIe Is used to store the names of hosts whIch wIII receIve emaII
ThIs Is a very compIex confIguratIon fIIe for SendmaII.
ThIs Is used to heIp the admInIstrator confIgure sendmaII so hopefuIIy you
won´t have to create your own
BasIc confIguratIon fIIes:
ContaIns entIre server processIng reIated commands.
ContaIns server resource InformatIon
Per dIrectory confIguratIon
AII of these fIIes are found In /etc/httpd/apache/conf or/etc/httpd/conf
-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, 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

ThIs fIIe wIII basIcaIIy tIe aII of the db fIIes together. Here Is asampIe /etc/named.conf
DIrectory "/var/named¨
Zone ".¨ {
Type hInt
FIIe "db.cache¨;
zone "¨ {
type master;
fIIe "¨;
zone "¨ {
type master;
fIIe "db.192.168.1¨;
zone "¨ {
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.
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.
The Start Of AuthorIty record sIgnaIs that the records foIIowIng the SOA RR contaIn
authorItatIve InformatIon for the domaIn.
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.

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

DetermInes the IntervaI durIng whIch a secondary server shouId retry contactIng the
prImary server If a request or a zone refresh faIIs
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.

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
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
ThIs poInts to a master name server of a subordInate zone
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
Used to assocIate names In the In- 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)

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

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

The client:
mount -t nfs ./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:
The /etc/exports fIIe offers more optIons whIch can be Iocated In man exports. A
more InvoIved /etc/exports fIIe mIght Iook IIke:
/home *
/prIvate (noaccess)
/usr/IocaI *
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.
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

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