You are on page 1of 6

LinuxAssignment

Exercise:1
1.LogonaLinuxmachineEnteryourlogin(username)andpasswordatrelevant
prompts.
2.EnterthesecommandsattheUNIXprompt,andtrytointerprettheoutput.Ask
questionsanddon'tbeafraidtoexperiment(asanormaluseryoucannotdomuch
harm):
echohelloworld

passwd

date

hostname
arch

unamea

dmesg|more (youmayneedtopressqtoquit)
uptime

whoami
who
id
last

finger

top (youmayneedtopressqtoquit)
echo$SHELL
echo{con,pre}{sent,fer}{s,ed}
man"automaticdoor"
manls (youmayneedtopressqtoquit)
manwho (youmayneedtopressqtoquit)
whocantellmewhyigotdivorced
lost
clear
cal2000
cal91752 (doyounoticeanythingunusual?)
bcl (typequit orpressCtrldtoquit)
echo5+4|bcl
yesplease (youmayneedtopressCtrlctoquit)
timesleep5
history

Exercise:2
Trythefollowingcommandsequence:
cd
pwd
lsal
cd.
pwd(wheredidthatgetyou?)
cd..
pwd
lsal
cd..
pwd
lsal
cd..
pwd(whathappensnow)
cd/etc
lsal|more
catpasswd
cd
pwd
2. Continuetoexplorethefilesystemtreeusingcd,ls,pwdandcat.Lookin/bin,
/usr/bin,/sbin,/tmpand/boot.Whatdoyousee?
3. Explore/dev.Canyouidentifywhatdevicesareavailable?Whicharecharacter
orientedandwhichareblockoriented?Canyouidentifyyourtty
(terminal)device(typingwhoamimighthelp);whoistheownerofyourtty
(uselsl)?
4. Explore/proc.Displaythecontentsofthefilesinterrupts,devices,cpuinfo,
meminfoanduptimeusingcat.Canyouseewhywesay/procisapseudo
filesystemwhichallowsaccesstokerneldatastructures?
5. Changetothehomedirectoryofanotheruserdirectly,usingcd~username.
6. Changebackintoyourhomedirectory.
7. Makesubdirectoriescalledworkandplay.
8. Deletethesubdirectorycalledwork.
9. Copythefile/etc/passwdintoyourhomedirectory.
10. Moveitintothesubdirectoryplay.
11. Changeintosubdirectoryplayandcreateasymboliclinkcalledterminalthat
pointstoyourttydevice.Whathappensifyoutrytomakeahardlinktothetty
device?
12. Whatisthedifferencebetweenlistingthecontentsofdirectoryplaywithlsl
andlsL?
13. Createafilecalledhello.txtthatcontainsthewords"helloworld".Canyouuse
"cp"using"terminal"asthesourcefiletoachievethesameeffect?
14. Copyhello.txttoterminal.Whathappens?
15. Imagineyouwereworkingonasystemandsomeoneaccidentallydeletedthels
command(/bin/ls).Howcouldyougetalistofthefilesinthecurrentdirectory?

Tryit.
16. Howwouldyoucreateandthendeleteafilecalled"$SHELL"?Tryit.
17. Howwouldyoucreateandthendeleteafilethatbeginswiththesymbol#?
Tryit.
18. Howwouldyoucreateandthendeleteafilethatbeginswiththesymbol?Try
it.
19. Whatistheoutputofthecommand:echo{con,pre}{sent,fer}{s,ed}?Now,
fromyourhomedirectory,copy/etc/passwdand/etc/groupintoyourhome
directoryinonecommandgiventhatyoucanonlytype/etconce.
20. Stillinyourhomedirectory,copytheentiredirectoryplaytoadirectorycalled
work,preservingthesymboliclink.
21. Deletetheworkdirectoryanditscontentswithonecommand.Acceptno
complaintsorqueries.
22. Changeintoadirectorythatdoesnotbelongtoyouandtrytodeleteallthe
files(avoid/procor/dev,justincase!)
23. Experimentwiththeoptionsonthelscommand.Whatdothed,i,RandF
optionsdo?

Exercise:3
Describethreedifferentwaysofsettingthepermissionsonafileordirectorytorrr.
Createafileandseeifthisworks.

1. Teamupwithapartner.Copy/bin/shtoyourhomedirectory.Type"chmod+s
sh".Checkthepermissionsonshinthedirectorylisting.Nowaskyourpartnerto
changeintoyourhomedirectoryandruntheprogram./sh.Askthemtorunthe
idcommand.What'shappened?Yourpartnercantypeexittoreturntotheir
shell.
2. Whatwouldhappenifthesystemadministratorcreatedashfileinthisway?
Whyisitsometimesnecessaryforasystemadministratortousethisfeature
usingprogramsotherthansh?
3. Deleteshfromyourhomedirectory(oratleasttodoachmodssh).
4. Modifythepermissionsonyourhomedirectorytomakeitcompletelyprivate.
Checkthatyourpartnercan'taccessyourdirectory.Nowputthepermissions
backtohowtheywere.
5. Typeumask000andthencreateafilecalledworld.txtcontainingthewords
"helloworld".Lookatthepermissionsonthefile.What'shappened?Nowtype
umask022andcreateafilecalledworld2.txt.Whenmightthisfeaturebe
useful?
6. Createafilecalled"hello.txt"inyourhomedirectoryusingthecommandcatu
>hello.txt.Askyourpartnertochangeintoyourhomedirectoryandruntailf
hello.txt.Nowtypeseverallinesintohello.txt.Whatappearsonyourpartner's
screen?
7. Usefindtodisplaythenamesofallfilesinthe/homesubdirectorytree.Canyou
dothiswithoutdisplayingerrorsforfilesyoucan'tread?
8. Usefindtodisplaythenamesofallfilesinthesystemthatarebiggerthan1MB.
9. Usefindandfiletodisplayallfilesinthe/homesubdirectorytree,aswellasa
guessatwhatsortofafiletheyare.Dothisintwodifferentways.
10. Usegreptoisolatethelinein/etc/passwdthatcontainsyourlogindetails.
11. Usefindandgrepandsorttodisplayasortedlistofallfilesinthe/home
subdirectorytreethatcontainthewordhellosomewhereinsidethem.
12. Uselocatetofindallfilenamesthatcontainthewordemacs.Canyoucombine
thiswithgreptoavoiddisplayingallfilenamescontainingthewordlib?
13. Createafilecontainingsomelinesthatyouthinkwouldmatchtheregular
expression:(^[09]{1,5}[azAz]+$)|noneandsomelinesthatyouthink
wouldnotmatch.Useegreptoseeifyourintuitioniscorrect.
14. Archivethecontentsofyourhomedirectory(includinganysubdirectories)
usingtarandcpio.Compressthetararchivewithcompress,andthecpioarchive
withgzip.Nowextracttheircontents.
15. OnLinuxsystems,thefile/dev/urandomisaconstantlygeneratedrandom
streamofcharacters.Canyouusethisfilewithodtoprintoutarandomdecimal
number?
16. Typemount(withnoparameters)andtrytointerprettheoutput.

Exercise:4
Archivethecontentsofyourhomedirectoryusingtar.Compressthetarfilewithgzip.Now
uncompressandunarchivethe.tar.gzfileusingcat,tarandgzipononecommandline.

1. Usefindtocompilealistofalldirectoriesinthesystem,redirectingtheoutput
sothatthelistofdirectoriesendsupinafilecalleddirectories.txtandthelistof
errormessagesendsupinafilecallederrors.txt.
2. Trythecommandsleep5.Whatdoesthiscommanddo?
3. Runthecommandinthebackgroundusing&.
4. Runsleep15intheforeground,suspenditwithCtrlzandthenputitintothe
backgroundwithbg.Typejobs.Typeps.Bringthejobbackintotheforeground
withfg.
5. Runsleep15inthebackgroundusing&,andthenusekilltoterminatethe
processbyitsjobnumber.Repeat,exceptthistimekilltheprocessbyspecifying
itsPID.
6. Runsleep15inthebackgroundusing&,andthenusekilltosuspendthe
process.Usebgtocontinuerunningtheprocess.
7. Startupanumberofsleep60processesinthebackground,andterminatethem
allatthesametimeusingthepkillcommand.
8. Useps,wandtoptoshowallprocessesthatareexecuting.
9. UsepsaeHtodisplaytheprocesshierarchy.Lookfortheinitprocess.Seeifyou
canidentifyimportantsystemdaemons.Canyoualsoidentifyyourshellandits
subprocesses?
10. Combinepsfaewithgreptoshowallprocessesthatyouareexecuting,with
theexceptionofthepsfaeandgrepcommands.
11. Startasleep300processrunninginthebackground.Logofftheserver,andlog
backinagain.Listalltheprocessesthatyouarerunning.Whathappenedtoyour
sleepprocess?Nowrepeat,exceptthistimestartbyrunningnohupsleep300.
12. Multiplejobscanbeissuedfromthesamecommandlineusingtheoperators;,
&&and||.Trycombiningthecommandscatnonexistentandechohellousing
eachoftheseoperators.Reversetheorderofthecommandsandtryagain.What
aretherulesaboutwhenthecommandswillbeexecuted?
13. Whatdoesthexargscommanddo?Canyoucombineitwithfindandgrepto
findyetanotherwayofsearchingallfilesinthe/homesubdirectorytreeforthe
wordhello?
14. Whatdoesthecutcommanddo?Canyouuseittogetherwithwtoproducea
listofloginnamesandCPUtimescorrespondingtoeachactiveprocess?Canyou
now(allonthesamecommandline)usesortandheadortailtofindtheuser
whoseprocessisusingthemostCPU?

Exercise:5
1. Edityourcopyofthedocumentusingvi.
2. Gototheendofthedocumentandtypeinthefollowingparagraph:

3.
4.
5.
6.
7.
8.

Joinedthelibrary.GotCareoftheSkin,OriginoftheSpecies,andabookbya
womanmymotherisalwaysgoingonabout.ItiscalledPrideandPrejudice,by
awomancalledJaneAusten.Icouldtellthelibrarianwasimpressed.Perhaps
sheisanintellectuallikeme.Shedidn'tlookatmyspot,soperhapsitisgetting
smaller.
Correctthethreespellingerrorsinthefirstthreelinesofthefirstparagraph(one
errorperline)andremovetheextra"Geography"inthe3rdlineofthefirst
paragraph.
Addthewords"Abouttime!"totheendofthesecondparagraph.
Deletethesentence"Timeflieslikeanarrowbutfruitflieslikeabanana"and
reformtheparagraph.
Replacealloccurrencesof"is"with"was".
Swapthetwoparagraphs.
Savethefileandquit.

You might also like