Answer Key To Linux
Answer Key To Linux
Answer Key To Linux
1he dump uLlllLy uses Jomp levels Lo deLermlne Lo whaL degree us wanL usr
sysLem backed up A dump level of 0 wlll copy flle sysLems ln Lhelr enLlreLy 1he
remalnlng dump levels perform lncremenLal backups only backlng up flles and
dlrecLorles LhaL have been creaLed or modlfled slnce Lhe lasL lowerlevel backup A
dump level of 1 wlll only back up flles LhaL have changed slnce Lhe lasL level 0 backup
1he dump level 2 ln Lurn wlll only back up flles
LhaL have changed slnce Lhe lasL level 1 backup (or 0 lf Lhere ls no level 1) and so on up
Lo dump level 9
We use Lhe rsor command Lo elLher resLore an enLlre flle sysLem or Lo [usL
reLrleve parLlcular flles resLore wlll exLracL flles or dlrecLorles from a backup archlve and
copy Lhem Lo Lhe currenL worklng dlrecLory Make sure us are ln Lhe dlrecLory us wanL
Lhe flles resLored Lo when us run resLore resLore wlll also generaLe any subdlrecLorles
as needed resLore has several opLlons for managlng Lhe resLore operaLlon
a C LeLs you check a backup by comparlng flles on a
flle sysLem wlLh Lhose ln a backup
b l 1he lnLeracLlve mode for resLorlng parLlcular flles
and dlrecLorles ln a backup A shell lnLerface ls
generaLed where Lhe user can use commands Lo speclfy
flles and dlrecLorles Lo resLore
c 8 Wlll lnsLrucL resLore Lo requesL a Lape LhaL ls parL of
a mulLlvolume backup from whlch Lo conLlnue Lhe
resLore operaLlon Pelpful when mulLlvolume resLore
operaLlons are lnLerrupLed
d r 8esLore a flle sysLem Make sure LhaL a newly
formaLLed parLlLlon has been mounLed and LhaL you
have changed Lo lLs Lop dlrecLory
b) llle securlLy
1he Llnux securlLy model ls based on Lhe one used on unlx sysLems and
ls as rlgld as Lhe unlx securlLy model (and someLlmes even more) whlch ls already
qulLe robusL Cn a Llnux sysLem every flle ls owned by a user and a group user 1here
ls also a Lhlrd caLegory of users Lhose LhaL are noL Lhe user owner and donL belong
Lo Lhe group ownlng Lhe flle lor each caLegory of users read wrlLe and execuLe
permlsslons can be granLed or denled
c) llle ermlsslons
AlLhough Lhere are already a loL of good securlLy feaLures bullL lnLo Llnuxbased
sysLems one very lmporLanL poLenLlal vulnerablllLy can exlsL when local access ls
granLed LhaL ls flle permlsslon based lssues resulLlng from a user noL asslgnlng Lhe
correcL permlsslons Lo flles and dlrecLorles
1he 8aslc llle ermlsslons are as follows
rm|ss|on Grops
Lach flle and dlrecLory has Lhree user based permlsslon groups
O ownr 1he Cwner permlsslons apply only Lhe owner of Lhe flle or dlrecLory
Lhey wlll noL lmpacL Lhe acLlons of oLher users
O grop 1he Croup permlsslons apply only Lo Lhe group LhaL has been asslgned
Lo Lhe flle or dlrecLory Lhey wlll noL effecL Lhe acLlons of oLher users
O f|| srs 1he All users permlsslons apply Lo all oLher users on Lhe sysLem Lhls
ls Lhe permlsslon group LhaL you wanL Lo waLch Lhe mosL
rm|ss|on 1yps
Lach flle or dlrecLory has Lhree baslc permlsslon Lypes
O rfd 1he 8ead permlsslon refers Lo a users capablllLy Lo read Lhe conLenLs of
Lhe flle
O wr| 1he WrlLe permlsslons refer Lo a users capablllLy Lo wrlLe or modlfy a flle
or dlrecLory
O c 1he LxecuLe permlsslon affecLs a users capablllLy Lo execuLe a flle or
vlew Lhe conLenLs of a dlrecLory
1 Lp|f|n fny on s|| of L|n |n df|| Jf fr d|ffrn fvf||fb| s||s?
Ans 8ourne Shell
1he 8ourne shell ls Lhe orlglnal unlx shell (command execuLlon program ofLen
called a commooJ lotetptetet) LhaL was developed aL A11 named for lLs developer
SLephen 8ourne Lhe 8ourne shell ls also known by lLs program name sb 1he shell
prompL (characLer dlsplayed Lo lndlcaLe readlness for lnpuL) used ls Lhe 5 symbol 1he
8ourne shell famlly lncludes Lhe 8ourne korn shell bash and zsh shells
8ourne Agaln Shell (8ash) ls Lhe free verslon of Lhe 8ourne shell dlsLrlbuLed wlLh Llnux
sysLems 8ash ls slmllar Lo Lhe orlglnal buL has added feaLures such as command llne
edlLlng
Zsh was developed by aul lalsLad as a replacemenL for boLh Lhe 8ourne and C shell lL
lncorporaLes feaLures of all Lhe oLher shells (such as flle name compleLlon and a hlsLory
mechanlsm) as well as new capablllLles Zsh ls consldered slmllar Lo Lhe korn shell
lalsLad lnLended Lo creaLe ln zsh a shell LhaL would do whaLever a programmer mlghL
reasonably hope lL would do Zsh ls popular wlLh advanced users
Along wlLh Lhe korn shell and Lhe C shell Lhe 8ourne shell remalns among Lhe Lhree
mosL wldely used and ls lncluded wlLh all unlx sysLems 1he 8ourne shell ls ofLen
consldered Lhe besL shell for developlng scrlpLs
1he dlfferenL shells avallable ln llnux are as follows
a) ash 1he AlmqulsL shell(also known as A Shell or ash) was orlglnally a
clone of Lhe 8ourne shell lL ls a fasL small CSlx compaLlble
unlx shell deslgned Lo replace Lhe 8ourne Shell lL dld noL
feaLure llne edlLlng or command hlsLory mechanlsms orlglnally
b) bash lL ls a unlx shell wrlLLen for Lhe Cnu pro[ecL 1he name of Lhe
acLual execuLable ls bash whlch ls an acronym for 8ourne agaln
shell 8ash ls Lhe defaulL shell on mosL Llnux sysLems as well as
on Mac CS x and lL can be run on mosL unlxLlke operaLlng
sysLems
c) csh 1he C shell ls a unlx shell developed by 8lll !oy for Lhe 8Su unlx
sysLem lLs synLax ls modeled afLer Lhe C programmlng language
and conLalns many added feaLure lmprovemenLs over Lhe
8ourne Shell
d) es 1he es shell ls a command llne lnLerpreLer LhaL uses a scrlpLlng
language slmllar Lo Lhe rc shell lL ls lnLended Lo provlde a fully
funcLlonal programmlng language as a unlx shell
e) ksh lL ls also known as korn shell lL ls a programmlng shell
compaLlble wlLh 8ourne shell buL supporLlng advanced
programmlng feaLure llke assoclaLlve arrays and floaLlng polnL
arlLhmeLlc
f) rc 1he rc shell ls Lhe command llne lnLerpreLer for verslon 10 unlx
lL resembles Lhe 8ourne shell buL lLs synLax ls somewhaL
slmpler lL was developed by 1om uuff who ls beLLer known for
a unusual C programmlng language consLrucL called uuff's
devlce
g) 1csh Lcsh ls a unlx shell largely based on and compaLlble wlLh Lhe C
shell 1hls shell lncorporaLes elemenLs from Lhe C programmlng
language lnLo Lhe shell scrlpLs
h) Zsh zsh shell ls an advanced shell LhaL lncorporaLes feaLures from
8ash Lcsh and korn shell provldlng advanced feaLures shared
memory eLc
20 Lp|f|n cond||onf| fnd |oop|ng sfmns |n s|| progrfmm|ng
Ans CondlLlonal SLaLemenLs
CondlLlonal sLaLemenLs are an lmporLanL parL of Lhe baslc bulldlng blocks of shell
scrlpLlng 1hese allow us Lo declde programmaLlcally wheLher Lo execuLe a block of sLaLemenLs
based on a loglcal LesL CondlLlonal sLaLemenLs are malnly used ln shell programs Lo declde
whlch parL of Lhe program Lo execuLe dependlng on speclfled condlLlons 1he condlLlonal
sLaLemenLs are as follows
1he lf SLaLemenL
1he lf sLaLemenL evaluaLes a loglcal expresslon Lo make a declslon An lf condlLlon has
Lhe followlng formaL ln bash
lf expresslon Lhen
SLaLemenLs
ellf expresslon Lhen
SLaLemenLs
else
SLaLemenLs
fl
1he lf condlLlons can be nesLed whlch means an lf condlLlon can conLaln anoLher lf condlLlon
wlLhln lL lL ls noL necessary for an lf condlLlon Lo have an ellf or else 1he else parL ls execuLed lf
none of Lhe expresslons LhaL are speclfled ln Lhe lf sLaLemenL are Lrue
1he word fl ls used Lo lndlcaLe Lhe end of Lhe lf sLaLemenLs whlch ls very useful lf we have
nesLed lf condlLlons ln such a case we should be able Lo maLch fl Lo lf Lo ensure LhaL all lf
sLaLemenLs are properly coded
Lg
lf $var"?es" Lhen
echo value ls ?es"
ellf $var no" Lhen
echo value ls no"
else
echo lnvalld value"
fl
1he Case SLaLemenL
1he case sLaLemenL ls used Lo execuLe sLaLemenLs dependlng on a dlscreLe value or a
range of values maLchlng Lhe speclfled varlable ln mosL cases lf we have a large number of
condlLlons Lhen we can use a case sLaLemenL lnsLead of an lf sLaLemenL
1he formaL of a case sLaLemenL ls as follows
case sLr ln
sLr1|sLr2)
SLaLemenLs
sLr3|sLr4)
SLaLemenLs
*)
SLaLemenLs
esac
Lg
#!/bln/bash
case $1 ln
01 | 1) echo MonLh ls !anuary"
02 | 2) echo MonLh ls lebruary"
03 | 3) echo MonLh ls March"
04 | 4) echo MonLh ls Aprll"
03 | 3) echo MonLh ls May"
06 | 6) echo MonLh ls !une"
07 | 7) echo MonLh ls !uly"
08 | 8) echo MonLh ls AugusL"
09 | 9) echo MonLh ls SepLember"
10) echo MonLh ls CcLober"
11) echo MonLh ls november"
12) echo MonLh ls uecember"
*) echo lnvalld parameLer"
esac
Looplng or lLeraLlon SLaLemenLs
Shell sclpLs wrlLLen ln bash can lmplemenL looplng or lLeraLlon sLaLemenLs 1he
common consLrucLs are as follows
O for
O whlle
O unLll
1he for sLaLemenL
1he for sLaLemenL has a number of formaLs 1he flrsL formaL ls as follows
for curvar ln llsL
do
SLaLemenLs
done
1hls form should be used lf we wanL Lo execuLe sLaLemenLs once for each value ln a llsL
1he second formaL ls as follows
for curvar
do
SLaLemenLs
done
ln Lhls form Lhe sLaLemenLs are execuLed once for each of Lhe poslLlonal parameLers passed Lo
Lhe shell program
Lg
#!/bln/bash
for fllename ln 'ls'
do
cp $fllename backup/$fllename
lf $? ne 0 Lhen
echo copy for $fllename falled"
fl
done
1he Whlle SLaLemenL
1he whlle sLaLemenL can be used Lo execuLe a serles of commands whlle a speclfled
condlLlon ls Lrue 1he loo LermlnaLes as soon as Lhe speclfled condlLlon evaluaLes Lo false lL ls
posslble LhaL Lhe loop wlll noL execuLe aL all lf Lhe speclfled condlLlon evaluaLes Lo false rlghL aL
Lhe beglnnlng
1he followlng frmaL ls used
whlle expresslon
do
SLaLemenLs
uone
Lg
#!/bln/bash
loopcounL 0
resulLo
whlle $loopcounL lL 3
do
loopcounL'expr $loopcounL +1'
lncremenL 'expr $loopcounL *2'
resulL'expr $resulL + $lncremenL'
done
echo resulL ls $resulL"
1he unLll sLaLemenL
1he unLll sLaLemenL can be used Lo execuLe a serles of commands unLll a speclfled
condlLlon ls Lrue 1he loop LermlnaLes as soon as Lhe speclfled condlLlon evaluaLes Lo Lrue
1he followlng formaL ls used
unLll expresslon
do
SLaLemenLs
done
Lg
#!/bln/bash
loopcounL 0
resulL0
unLll $loopcounL ge 3
do
loopcounL'expr $loopcounL +1'
lncremenL 'expr $loopcounL*2'
resulL'expr $resulL + $lncremenL'
done
echo"resulL ls $resulL"
1he selecL sLaLemenL
1he selecL sLaLemenL ls used Lo generaLe a menu llsL lf you are wrlLlng a shell program
LhaL expecLs onllne lnpuL from Lhe user 1he formaL of Lhe selecL sLaLemenL ls as follows
selecL lLem ln lLemllsL
do
SLaLemenLs
done
Lg
#!/bln/bash
selecL lLem ln conLlnue flnlsh
do
lf $lLem "flnlsh" Lhen
break
fl
done
21 Lp|f|n f|| s|mp| f||r commfnds
Ans A fllLer Lakes Lhe sLandard lnpuLperforms some acLlon on lLand Lhen reLurns lL as a
sLandard ouLpuL Llnux has a large number of fllLers Some useful ones are Lhe commands
awkgrepsedspell and wc
1he flrsL fllLer grep removes any dlrecLorles from Lhe llsL by excludlng any llnes LhaL sLarL wlLh a
leadlng d
grep v d"
1he nexL fllLer awk exLracLs Lhe requlred flelds fllename username access daLe and Llme and
flle slze lL also places Lhe flle slze aL Lhe sLarL llne so LhaL Lhe daLa ls ready for sorLlng
awk 'prlnL $3 $8 $3 $6 $7'
obvlously Lhe nexL fllLer sorLs Lhe daLa
sorL nr
And Lhe flnal fllLer anoLher awk formaLs Lhe daLa ready Lo be emalled
awk 'prlnL $2 "L" $3 "L" $4 $3 "L" $1'
1here are many llnux fllLer commands ln addlLlon Lo awkgrep and sorL1wo fllLers Lo conslder
are Lr(LranslaLe) and sed(sLream edlL) ln each caseboLh Lhe commands allow us Lo modlfy a
sLream Lr for slmple changes and sed for more complex ones We can use LrazAZ Lo
converL everyLhlng Lo uppercase or sed s/"*"//g Lo remove asLerlsks from Lhe names of
execuLable flles
AnoLher lmporLanL fllLer ls Leewhlch enables us Lo spllL a sLream beLween sLandard ouLpuL and
a flle for example
ls l | Lee fllelsL | wc 1
1hls wlll creaLe a flle(fllelsL)conLalnlng Lhe resulL from lsl and wlll dlsplay Lhe number of flles Lo
Lhe screen
22 Lp|f|n k w|ndows conf|grf|on Compfr kDL fnd GNCML grfp|cf| |nrffcs
Ans x wlndows ls Lhe sLandard graphlcal user lnLerface for Llnux Llke oLher graphlcal user
lnLerfaces such as MlcrosofL Wlndows and Mac CS x leLs you lnLeracL wlLh programs by uslng a
mouse (or oLher polnLlng devlce) Lo polnL and cllck provldlng a slmple means of communlcaLlng
wlLh your compuLer x wlndows ls a remarkable and very modern sofLware sysLem a cross
plaLform neLworkorlenLed graphlcal user lnLerface lL runs on a wlde varleLy of plaLforms
lncludlng essenLlally every varleLy of unlx x CllenLs are avallable for use for example under
Wlndows 3x 9x and n1 1he sophlsLlcaLed neLworklng capablllLles of x leL you run a program
on one compuLer whlle vlewlng Lhe graphlcal ouLpuL on anoLher compuLer connecLed Lo Lhe
flrsL vla a neLwork WlLh Lhe advenL of Lhe lnLerneL whlch lnLerconnecLed a slzable fracLlon of
Lhe compuLers on Lhe planeL x achleved a new helghL of lmporLance and power
lnsLalllng x wlndows
CeLLlng a proper x Wlndow SysLem up and runnlng used Lo be a real challenge on Llnux
almosL a rlLe of passage 1oday devlce drlvers are avallable for a much wlder array of hardware
and conflguraLlon Lools Lo asslsL ln Lhe seLup process have greaLly lmproved Whlle sLlll Lrlcky aL
Llmes especlally wlLh unusual hardware x seLup and conflguraLlon ls no longer Lhe daunLlng
process lL once was and should be relaLlvely easy
?oull go Lhrough Lwo sLages before you have x successfully runnlng 1he flrsL sLage lnvolves
lnsLalllng Lhe needed programs LhaL enable x Lo run 1hese can be grouped lnLo several
caLegorles
O 8aslc xlree86 program
O x servers
O Wlndow Managers
O AppllcaLlons
O lonLs
1hls sLage ls very sLralghLforward and can even be done as parL of Lhe baslc lnsLallaLlon process
lf you selecL Lhe relevanL x packages durlng LhaL sLep
ln Lhe second sLage you conflgure x Lo run properly on your sysLem 1hls ls a maLLer of
ldenLlfylng an x server compaLlble wlLh your graphlcs card and Lunlng Lhe server for your
graphlcs card lf you have a common card and all Lhe documenLaLlon for lL Lhls second sLage wlll
be relaLlvely slmple Mlsslng lnformaLlon makes Lhe process harder buL noL lmposslble
Conflgurlng x wlndows
When you lnsLall Lhe setvetcommoo package xf86conflg ls auLomaLlcally launched
Powever you can launch Lhe program any Llme you llke 1o do so log ln as rooL and Lype Lhe
command
xf86conflg
kuL deskLop
kuL (Lhe k ueskLop LnvlronmenL) ls a freely avallable deskLop LhaL lncludes kWM Lhe k
Wlndow Manager as an lnLegral componenL kuL provldes a flle manager a help sysLem a
conflguraLlon uLlllLy and a varleLy of accessorles and appllcaLlons lncludlng
O Cames such as kmlnes kpoker and kLeLrls
O Craphlcal appllcaLlons such as kfracL a fracLal generaLor and kvlew an lmage vlewer
O MulLlmedla appllcaLlons such as kmlx a sound mlxer and kmedla a medla player
O neLwork appllcaLlons such as kmall a mall cllenL knu a neLwork uLlllLy and krn a news
cllenL
AlLhough kuL ls freely redlsLrlbuLable kuL uses Lhe C1 wldgeL seL Lo creaLe user lnLerface
conLrols 1hls presenLs a problem because C1 ls dlsLrlbuLed under a nonfree llcense LhaL many
developers dlsllke 1herefore Lhe mosL popular deskLop envlronmenL ln Lhe uS has been and
conLlnues Lo be CnCML raLher Lhan kuL
CnCML deskLop
CnCML ls a freely avallable deskLop LhaL can be used wlLh any of several wlndow
managers lncludlng LnllghLenmenL unllke kuL CnCML ls open source sofLware
Cne of CnCMLs mosL lnLeresLlng feaLures ls sesslon awareness When you reenLer CnCML lL
reconflgures your deskLop Lo maLch Lhe sLaLe aL Lhe Llme you exlLed by launchlng each
appllcaLlon LhaL was open when you exlLed CnCML even resLores each appllcaLlon Lo lLs former
sLaLe by for example movlng Lo Lhe page LhaL was open when you exlLed
CnCML provldes deskLop Lools slmllar Lo Lhose of kuL lncludlng
O Cames such as lreeCell CnoboLs CnomeLrls and Cnome Mlnes
O 1he Cnu lmage ManlpulaLlon rogram (ClM)
O neLwork appllcaLlons such as Mallman whlch helps you Lrack your malllng llsLs 1alk whlch
leLs you exchanged Lyped messages wlLh anoLher user ln real Llme and Synchronlze whlch
leLs you synchronlze flles on mulLlple sysLems
O MulLlmedla appllcaLlons such as Audlo Mlxer and Cu layer
O Ceneral appllcaLlons such as gLdlL a LexL edlLor neLscape navlgaLor a Llnux verslon of Lhe
popular browser and Cnumerlc a spreadsheeL
O uLlllLles for conflgurlng CnCML and your Llnux sysLem