You are on page 1of 151

TheUnixandGNU/Linuxcommandline

TheUnixandGNU/Linuxcommandline
MichaelOpdenacker FreeElectrons http://freeelectrons.com

CreatedwithOpenOffice.org2.0
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

Rightstocopy
Copyright20062004 MichaelOpdenacker michael@freeelectrons.com Documentsources,updatesandtranslations:
http://freeelectrons.com/training/intro_unix_linux

AttributionShareAlike2.0 Youarefree tocopy,distribute,display,andperformthework tomakederivativeworks tomakecommercialuseofthework Underthefollowingconditions Attribution.Youmustgivetheoriginalauthorcredit. ShareAlike.Ifyoualter,transform,orbuilduponthiswork, youmaydistributetheresultingworkonlyunderalicense identicaltothisone. Foranyreuseordistribution,youmustmakecleartoothersthe licensetermsofthiswork. Anyoftheseconditionscanbewaivedifyougetpermissionfrom thecopyrightholder. Yourfairuseandotherrightsareinnowayaffectedbytheabove. Licensetext:http://creativecommons.org/licenses/bysa/2.0/legalcode

Corrections,suggestions,contributionsand translationsarewelcome!

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

Bestviewedwith...
ThisdocumentisbestviewedwitharecentPDFreader orwithOpenOffice.orgitself! Takeadvantageofinternalorexternalhyperlinks. So,donthesitatetoclickonthem! Findpagesquicklythankstoautomaticsearch Usethumbnailstonavigateinthedocumentinaquickway IfyourereadingapaperorHTMLcopy,youshouldgetyour copyinPDForOpenOffice.orgformaton http://freeelectrons.com/training/intro_unix_linux!

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

Commandmementosheet
Itisausefulcompaniontothis presentation. Examplesforthemostuseful commandsaregiveninjustonesheet. Suggestionsforuse Stickthissheetonyourwall,useitas desktopwallpaper,makeitamouse mat,printitonclothing,sliceitinto bookmarks... Caution Storeawayfrommice!

Getiton http://freeelectrons.com/training/intro_unix_linux

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

TrainingContents(1)
Shells,filesystemandfilehandling Everythingisafile GNU/Linuxfilesystemstructure Commandlineinterpreters Handlingfilesanddirectories Displaying,scanningandsortingfiles Symbolicandhardlink Fileaccessrights

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

Trainingcontents(2)
StandardI/O,redirections,pipes Standardinputandoutput,redirectingtofiles Pipes:redirectingstandardoutputtoothercommands Standarderror

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

TrainingContents(3)
Taskcontrol Fullcontrolontasks Executinginbackground,suspending,resumingandaborting Listofactivetasks Killingprocesses Environmentvariables PATHenvironmentvariables Shellaliases,.bashrcfile

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

Trainingcontents(4)
Miscellaneous

Texteditors Compressingandarchiving Printingfiles Comparingfilesanddirectories Lookingforfiles Gettinginformationaboutusers

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

Trainingcontents(5)
Systemadministrationbasics Fileownership Settingupnetworking Filesystems:creatingandmounting Goingfurther Gettinghelp,accessingmanualpages SearchingtheInternetforresources

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

GNU/LinuxandFreeSoftware
ThispresentationincludedanintroductiontoFreeSoftware andOpenSource:operatingsystems,applications,key projectsandrulesforsuccess. Itisnowavailableasaseparatepresentation: http://freeelectrons.com/articles/freesw

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

10

TheUnixandGNU/Linuxcommandline

Unixfilesystem

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

11

Everythingisafile
AlmosteverythinginUnixisafile! Regularfiles Directories Directoriesarejustfiles listingasetoffiles Symboliclinks Filesreferringtothenameof anotherfile Devicesandperipherals Readandwritefromdevicesas withregularfiles Pipes Usedtocascadeprograms cat*.log|greperror Sockets Interprocesscommunication

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

12

Filenames
FilenamefeaturessincethebeginningofUnix Casesensitive Noobviouslengthlimit Cancontainanycharacter(includingwhitespace,except/). Filetypesstoredinthefile(magicnumbers). Filenameextensionsnotneededandnotinterpreted.Justusedfor userconvenience. Filenameexamples: README .bashrc index.htm index.html WindowsBuglist index.html.old

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

13

Filepaths
Apathisasequenceofnesteddirectorieswithafileordirectoryat theend,separatedbythe/character Relativepath:documents/fun/microsoft_jokes.html Relativetothecurrentdirectory Absolutepath:/home/bill/bugs/crash9402031614568 /:rootdirectory. Startofabsolutepathsforallfilesonthesystem(evenforfileson removabledevicesornetworkshared).

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

14

GNU/Linuxfilesystemstructure(1)
Notimposedbythesystem.Canvaryfromonesystemtotheother, evenbetweentwoGNU/Linuxinstallations! / /bin/ /boot/ /dev/ /etc/ /home/ /lib/ Rootdirectory Basic,essentialsystemcommands Kernelimages,initrdandconfigurationfiles Filesrepresentingdevices /dev/hda:firstIDEharddisk Systemconfigurationfiles Userdirectories Basicsystemsharedlibraries

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

15

GNU/Linuxfilesystemstructure(2)
/lost+found /mnt/ /opt/ /proc/ /root/ /sbin/ /sys/ Corruptfilesthesystemtriedtorecover Mountedfilesystems /mnt/usbdisk/,/mnt/windows/... Specifictoolsinstalledbythesysadmin /usr/local/oftenusedinstead Accesstosysteminformation /proc/cpuinfo,/proc/version... rootuserhomedirectory Administratoronlycommands Systemanddevicecontrols (cpufrequency,devicepower,etc.)

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

16

GNU/Linuxfilesystemstructure(3)
/tmp/ /usr/ /usr/local/ /var/ Temporaryfiles Regularusertools(notessentialtothesystem) /usr/bin/,/usr/lib/,/usr/sbin... Specificsoftwareinstalledbythesysadmin (oftenpreferredto/opt/) Datausedbythesystemorsystemservers /var/log/,/var/spool/mail(incoming mail),/var/spool/lpd(printjobs)...

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

17

TheUnixandGNU/Linuxcommandline

Shellsandfilehandling

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

18

Commandlineinterpreters
Shells:toolstoexecuteusercommands Calledshellsbecausetheyhidethedetailsonthe underlyingoperatingsystemundertheshell'ssurface. Commandsareinputinatextterminal,eitherawindowina graphicalenvironmentoratextonlyconsole. Resultsarealsodisplayedontheterminal.Nographicsare neededatall. Shellscanbescripted:providealltheresourcestowrite complexprograms(variable,conditionals,iterations...)

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

19

Wellknownshells
Mostfamousandpopularshells sh:TheBourneshell(obsolete) Traditional,basicshellfoundonUnixsystems,bySteveBourne. csh:TheCshell(obsolete) OncepopularshellwithaClikesyntax tcsh:TheTCshell(stillverypopular) ACshellcompatibleimplementationwithevolvedfeatures(command completion,historyeditingandmore...) bash:TheBourneAgainshell(mostpopular) Animprovedimplementationofshwithlotsofaddedfeaturestoo.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

20

fish:agreatnewshell
TheFriendlyInteractiveSHell http://roo.noip.org/fish/ Standardfeatures:history,commandandfilecompletion... Brandnewfeatures:commandoptioncompletion,command completionwithshortdescription,syntaxhighlighting.. Easiertoanyopenfiles:openbuiltincommand. Muchsimplerandconsistentsyntax(notPOSIXcompliant) Makesiteasiertocreateshellscripts. Commandlinebeginnerscanlearnmuchfaster! Evenexperiencedusersshouldfindthisshellveryconvenient.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

21

lscommand
Liststhefilesinthecurrentdirectory,inalphanumericorder, exceptfilesstartingwiththe.character. lsa(all) Listsallthefiles(including.* files) lsl(long) Longlisting(type,date,size, owner,permissions) lst(time) Liststhemostrecentfilesfirst lsS(size) Liststhebiggestfilesfirst lsr(reverse) Reversesthesortorder lsltr(optionscanbe combined) Longlisting,mostrecentfilesat theend

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

22

Filenamepatternsubstitutions
Betterintroducedbyexamples! ls*txt Theshellfirstreplaces*txtbyallthefileanddirectorynames endingbytxt(including.txt),exceptthosestartingwith., andthenexecutesthelscommandline. lsd.* Listsallthefilesanddirectoriesstartingwith. dtellslsnottodisplaythecontentsofdirectories. cat?.log Displaysallthefileswhichnamesstartby1characterandendby .log

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

23

Specialdirectories(1)
./ Thecurrentdirectory.Usefulforcommandstakingadirectory argument.Alsosometimesusefultoruncommandsinthecurrent directory(seelater). So./readme.txtandreadme.txtareequivalent. ../ Theparent(enclosing)directory.Alwaysbelongstothe.directory (seelsa).Onlyreferencetotheparentdirectory. Typicalusage: cd..

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

24

Specialdirectories(2)
~/ Notaspecialdirectoryindeed.Shellsjustsubstituteitbythe homedirectoryofthecurrentuser. Cannotbeusedinmostprograms,asitisnotarealdirectory. ~sydney/ Similarly,substitutedbyshellsbythehomedirectoryofthe sydneyuser.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

25

Thecdandpwdcommands
cd<dir> Changethecurrentdirectoryto<dir>. pwd Displaysthecurrentdirectory("workingdirectory").

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

26

Thecpcommand
cp<source_file><target_file> Copiesthesourcefiletothetarget. cpfile1file2file3...dir Copiesthefilestothetargetdirectory(lastargument). cpi(interactive) Asksforuserconfirmationifthetargetfilealreadyexists cpr<source_dir><target_dir>(recursive) Copiesthewholedirectory.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

27

Smartdirectorycopywithrsync
rsync(remotesync)hasbeendesignedtokeepinsync directorieson2machineswithalowbandwidthconnection.
Onlycopiesfilesthathavechanged.Fileswiththesamesizearecompared bychecksums. Onlytransferstheblocksthatdifferwithinafile! Cancompressthetransferredblocks Preservessymboliclinksandfilepermissions:alsoveryusefulforcopieson thesamemachine. Canworkthroughssh(secureremoteshell).Veryusefultoupdatethe contentsofawebsite,forexample.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

28

rsyncexamples(1)
rsynca/home/arvin/sd6_agents//home/sydney/misc/

a:archivemode.EquivalenttorlptgoD...easywaytotellyouwant recursionandwanttopreservealmosteverything.
rsyncPavdelete/home/steve/ideas//home/bill/my_ideas/

P:partial(keeppartiallytransferredfiles)andprogress (showprogressduringtransfer) delete:deletefilesinthetargetwhichdon'texistinthesource. Caution:directorynamesshouldendwith/.Otherwise,yougeta my_ideas/ideas/directoryatthedestination.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

29

rsyncexamples(2)
Copyingtoaremotemachine rsyncPav/home/bill/legal/arguments/\ bill@www.sco.com:/home/legal/arguments/ Userbillwillbepromptedforapassword. Copyingfromaremotemachinethroughssh rsyncPavessh homer@tank.duff.com/prod/beer/\ fridge/homer/beer/ Userhomerwillbepromptedforhissshkeypassword.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

30

mvandrmcommands
mv<old_name><new_name> (move) Renamesthegivenfileordirectory. mvi(interactive) Ifthenewfilealreadyexits,asksforuserconfirm rmfile1file2file3... (remove) Removesthegivenfiles. rmi(interactive) Alwaysaskforuserconfirm. rmrdir1dir2dir3(recursive) Removesthegivendirectorieswithalltheircontents.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

31

Creatingandremovingdirectories
mkdirdir1dir2dir3...(makedir) Createsdirectorieswiththegivennames. rmdirdir1dir2dir3...(removedir) Removesthegivendirectories Safe:onlyworkswhendirectoriesandempty. Alternative:rmr(doesn'tneedemptydirectories).

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

32

Displayingfilecontents
Severalwaysofdisplayingthecontentsoffiles. catfile1file2file3...(concatenate) Concatenatesandoutputsthecontentsofthegivenfiles. morefile1file2file3... Aftereachpage,askstheusertohitakeytocontinue. Canalsojumptothefirstoccurrenceofakeyword (/command). lessfile1file2file3... Doesmorethanmorewithless. Doesn'treadthewholefilebeforestarting. Supportsbackwardmovementinthefile(?command).

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

33

Theheadandtailcommands
head[<n>]<file> Displaysthefirst<n>lines(or10bydefault)ofthegivenfile. Doesn'thavetoopenthewholefiletodothis! tail[<n>]<file> Displaysthelast<n>lines(or10bydefault)ofthegivenfile. NoneedtoloadthewholefileinRAM!Veryusefulforhugefiles. tailf<file>(follow) Displaysthelast10linesofthegivenfileandcontinuestodisplaynewlines whentheyareappendedtothefile. Veryusefultofollowthechangesinalogfile,forexample. Examples headwindows_bugs.txt tailfoutlook_vulnerabilities.txt

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

34

Thegrepcommand
grep<pattern><files> Scansthegivenfilesanddisplaysthelineswhichmatchthegivenpattern. greperror*.log Displaysallthelinescontainingerrorinthe*.logfiles grepierror*.log Same,butcaseinsensitive greprierror. Same,butrecursivelyinallthefilesin.anditssubdirectories grepvinfo*.log Outputsallthelinesinthefilesexceptthosecontaininginfo.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

35

Thesortcommand
sort<file> Sortsthelinesinthegivenfileincharacterorderand outputsthem. sortr<file> Same,butinreverseorder. sortru<file> u:unique.Same,butjustoutputsidenticallinesonce. Morepossibilitiesdescribedlater!

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

36

Symboliclinks
Asymboliclinkisaspecialfilewhichisjustareferencetothe nameofanotherone(fileordirectory): Usefultoreducediskusageandcomplexitywhen2fileshavethe samecontent. Example:
anakin_skywalker_biography>darth_vador_biography

Howtoidentifysymboliclinks:
lsldisplays>andthelinkedfilename. GNUlsdisplayslinkswithadifferentcolor.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

37

Creatingsymboliclinks
Tocreateasymboliclink(sameorderasincp): lnsfile_namelink_name Tocreatealinkwithtoafileinanotherdirectory,withthe samename: lns../README.txt Tocreatemultiplelinksatonceinagivendirectory: lnsfile1file2file3...dir Toremovealink: rmlink_name Ofcourse,thisdoesn'tremovethelinkedfile!

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

38

Hardlinks
Thedefaultbehaviorforlnistocreatehardlinks Ahardlinktoafileisaregularfilewithexactlythesame physicalcontents Whiletheystillsavespace,hardlinkscan'tbedistinguished fromtheoriginalfiles. Ifyouremovetheoriginalfile,thereisnoimpactonthehard linkcontents. Thecontentsareremovedwhentherearenomorefiles(hard links)tothem.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

39

Filesnamesandinodes
Makeshardandsymbolic(soft)linkseasiertounderstand!
Users Filenameinterface

Softlink

rm

File Inode

Hardlink
rm

Inode interface Filesystem

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

40

Fileaccessrights
Uselsltocheckfileaccessrights
3typesofaccessrights Readaccess(r) Writeaccess(w) Executerights(x) 3typesofaccesslevels User(u):fortheownerofthe file Group(g):eachfilealsohasa groupattribute,corresponding toagivenlistofusers Others(o):forallotherusers

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

41

Accessrightconstraints
xwithoutrislegalbutisuseless Youhavetobeabletoreadafiletoexecuteit. Bothrandxpermissionsneededfordirectories: xtoenter,rtolistitscontents. Youcan'trename,remove,copyfilesinadirectoryifyoudon't havewaccesstothisdirectory. Ifyouhavewaccesstoadirectory,youCANremoveafileevenif youdon'thavewriteaccesstothisfile(rememberthatadirectory isjustafiledescribingalistoffiles).Thisevenletsyoumodify (remove+recreate)afileevenwithoutwaccesstoit.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

42

Accessrightsexamples
rwrr Readableandwritableforfileowner,onlyreadableforothers rwr Readableandwritableforfileowner,onlyreadableforusers belongingtothefilegroup. drwx Directoryonlyaccessiblebyitsowner rx Fileexecutablebyothersbutneitherbyyourfriendsnorby yourself.Niceprotectionsforatrap...

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

43

chmod:changingpermissions
chmod<permissions><files> 2formatsforpermissions: Octalformat(abc): a,b,c=r*4+w*2+x(r,w,x:booleans) Example:chmod644<file> (rwforu,rforgando) Orsymbolicformat.Easytounderstandbyexamples: chmodgo+r:addreadpermissionstogroupandothers. chmoduw:removewritepermissionsfromuser. chmodax:(a:all)removeexecutepermissionfromall.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

44

Morechmod(1)
chmodRa+rXlinux/ Makeslinuxandeverythinginitavailableto everyone! R:applychangesrecursively X:x,butonlyfordirectoriesandfilesalreadyexecutable Veryusefultoopenrecursiveaccesstodirectories, withoutaddingexecutionrightstoallfiles.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

45

Morechmod(2)
chmoda+t/tmp t:(sticky).Specialpermissionfordirectories,allowing onlythedirectoryandfileownertodeleteafileina directory. Usefulfordirectorieswithwriteaccesstoanyone, like/tmp. Displayedbylslwithatcharacter.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

46

TheUnixandGNU/Linuxcommandline

StandardI/O,redirections,pipes

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

47

Standardoutput
Moreaboutcommandoutput Allthecommandsoutputtingtextonyourterminaldoitby writingtotheirstandardoutput. Standardoutputcanbewritten(redirected)toafileusingthe >symbol Standardoutputcanbeappendedtoanexistingfileusingthe >>symbol

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

48

Standardoutputredirectionexamples
ls~saddam/*>~gwb/weapons_mass_destruction.txt catobiwan_kenobi.txt>starwars_biographies.txt cathan_solo.txt>>starwars_biographies.txt echoREADME:Nosuchfileordirectory>README Usefulwayofcreatingafilewithoutatexteditor. NiceUnixjoketoointhiscase.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

49

Standardinput
Moreaboutcommandinput Lotsofcommands,whennotgiveninputarguments,cantaketheir inputfromstandardinput. sort windows linux [Ctrl][D] linux windows sorttakesitsinputfrom thestandardinput:inthiscase, whatyoutypeintheterminal (endedby[Ctrl][D])

sort<participants.txt Thestandardinputofsortistakenfromthegivenfile.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

50

Pipes
Unixpipesareveryusefultoredirectthestandardoutputofa commandtothestandardinputofanotherone. Examples
cat*.log|grepierror|sort greprierror.|grepvignored|sortu\ >serious_errors.log cat/home/*/homework.txt|grepmark|more

ThisoneofthemostpowerfulfeaturesinUnixshells!

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

51

Theteecommand
tee[a]file Theteecommandcanbeusedtosendstandardoutput tothescreenandtoafilesimultaneously. make|teebuild.log Runsthemakecommandandstoresitsoutputto build.log. makeinstall|teeabuild.log Runsthemakeinstallcommandandappendsits outputtobuild.log.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

52

Standarderror
Errormessagesareusuallyoutput(iftheprogramiswellwritten) tostandarderrorinsteadofstandardoutput. Standarderrorcanberedirectedthrough2>or2>> Example: catf1f2nofile>newfile2>errfile Note:1isthedescriptorforstandardoutput,so1>isequivalentto >. Canredirectbothstandardoutputandstandarderrortothesame fileusing&>: catf1f2nofile&>wholefile

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

53

Theyescommand
Usefultofillstandardinputwithalwaysthesamestring. yes<string>|<command> Keepsfillingthestandardinputof<command>with <string>(ybydefault). Examples yes|rmrdir/ bank>yesno|credit_applicant yes""|makeoldconfig (equivalenttohitting[Enter]toacceptalldefaultsettings)

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

54

Specialdevices(1)
Devicefileswithaspecialbehaviororcontents /dev/null Thedatasink!Discardsalldatawrittentothisfile. Usefultogetridofunwantedoutput,typicallyloginformation: mplayerblack_adder_4th.avi&>/dev/null /dev/zero Readsfromthisfilealwaysreturn\0characters Usefultocreateafilefilledwithzeros: ddif=/dev/zeroof=disk.imgbs=1kcount=2048

Seemannullormanzerofordetails

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

55

Specialdevices(2)
/dev/random Returnsrandombyteswhenread.Mainlyusedbycryptographic programs.Usesinterruptsfromsomedevicedriversassourcesof truerandomness(entropy). Readscanbeblockeduntilenoughentropyisgathered. /dev/urandom Forprogramsforwhichpseudorandomnumbersarefine. Alwaysgeneratesrandombytes,evenifnotenoughentropyis available(inwhichcaseitispossible,thoughstilldifficult,to predictfuturebytesequencesfrompastones). Seemanrandomfordetails.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

56

TheUnixandGNU/Linuxcommandline

Taskcontrol

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

57

Fullcontrolontasks
Sincethebeginning,Unixsupportstruepreemptive multitasking. Abilitytorunmanytasksinparallel,andabortthemevenif theycorrupttheirownstateanddata. Abilitytochoosewhichprogramsyourun. Abilitytochoosewhichinputyourprogramstakes,and wheretheiroutputgoes.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

58

Processes
EverythinginUnixisafile EverythinginUnixthatisnotafileisaprocess Processes Instancesofarunningprograms Severalinstancesofthesameprogramcanrunatthesametime Dataassociatedtoprocesses: Openfiles,allocatedmemory,stack,processid,parent,priority,state...

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

59

Runningjobsinbackground
Sameusagethroughoutalltheshells Useful
Forcommandlinejobswhichoutputcanbeexaminedlater, especiallyfortimeconsumingones. Tostartgraphicalapplicationsfromthecommandlineand thencontinuewiththemouse.

Startingatask:add&attheendofyourline:
find_prince_charmingcutecleverrich&

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

60

Backgroundjobcontrol
jobs Returnsthelistofbackgroundjobsfromthesameshell
[1]Running~/bin/find_meaning_of_lifewithoutgod& [2]+Runningmakemistakes&

fg fg%<n> Putsthelast/nthbackgroundjobinforegroundmode Movingthecurrenttaskinbackgroundmode: [Ctrl]Z bg kill%<n> Abortsthenthjob.


TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

61

Jobcontrolexample
>jobs [1]Running~/bin/find_meaning_of_lifewithoutgod& [2]+Runningmakemistakes& >fg makemistakes >[Ctrl]Z [2]+Stoppedmakemistakes >bg [2]+makemistakes& >kill%1 [1]+Terminated~/bin/find_meaning_of_lifewithoutgod

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

62

Listingallprocesses
...whatevershell,scriptorprocesstheyarestartedfrom psux Listsalltheprocessesbelongingtothecurrentuser psaux(Note:psedfonSystemVsystems) Listsalltheprocessesrunningonthesystem
psaux|grepbart|grepbash USERPID%CPU%MEMVSZRSSTTYSTATSTARTTIMECOMMAND bart30390.00.259161380pts/2S14:350:00/bin/bash bart31340.00.253881380pts/3S14:360:00/bin/bash bart31900.00.263681360pts/4S14:370:00/bin/bash bart34160.00.000pts/2RW15:070:00[bash] PID: VSZ: RSS: TTY: STAT: Processid Virtualprocesssize(code+data+stack) Processresidentsize:numberofKBcurrentlyinRAM Terminal Status:R(Runnable),S(Sleep),W(paging),Z(Zombie)...

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

63

Liveprocessactivity
topDisplaysmostimportantprocesses,sortedbycpupercentage
top15:44:33up1:11,5users,loadaverage:0.98,0.61,0.59 Tasks:81total,5running,76sleeping,0stopped,0zombie Cpu(s):92.7%us,5.3%sy,0.0%ni,0.0%id,1.7%wa,0.3%hi,0.0%si Mem:515344ktotal,512384kused,2960kfree,20464kbuffers Swap:1044184ktotal,0kused,1044184kfree,277660kcached PIDUSERPRNIVIRTRESSHRS%CPU%MEMTIME+COMMAND 3809jdoe250625639321312R93.80.80:21.49bunzip2 2769root160157m80m90mR2.716.05:21.01X 3006jdoe1503092815m27mS0.33.00:22.40kdeinit 3008jdoe16056248924468S0.30.20:06.59autorun 3034jdoe1502676412m24mS0.32.50:12.68kscd 3810jdoe16028929161620R0.30.20:00.06top

Youcanchangethesortingorderbytyping M:Memoryusage,P:%CPU,T:Time. Youcankillataskbytypingkandtheprocessid.


TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

64

Killingprocesses(1)
kill<pids> Sendsanabortsignaltothegivenprocesses.Letsprocessessave dataandexitbythemselves.Shouldbeusedfirst.Example: kill3039313431903416 kill9<pids> Sendsanimmediateterminationsignal.Thesystemitself terminatestheprocesses.Usefulwhenaprocessisreallystuck (doesn'tanswertokill1). kill91 Killsalltheprocessesofthecurrentuser.1:meansallprocesses.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

65

Killingprocesses(2)
killall[<signal>]<command> Killsallthejobsrunning<command>.Example: killallbash xkill Letsyoukillagraphicalapplicationbyclickingonit! Veryquick!Convenientwhenyoudon'tknowtheapplication commandname.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

66

Recoveringfromstuckgraphics
Ifyourgraphicalsessionisstuckandyoucannolongertypeinyour terminals,don'treboot! Itisverylikelythatyoursystemisstillfine.Trytoaccessatextconsoleby pressingthe[Ctrl][Alt][F1]keys (or[F2],[F3]formoretextconsoles) Inthetextconsole,youcantrytokilltheguiltyapplication. Oncethisisdone,youcangobacktothegraphicsessionbypressing [Ctrl][Alt][F5]or[Ctrl][Alt][F7](dependingonyour distribution) Ifyoucan'tidentifythestuckprogram,youcanalsokillallyourprocesses: kill91 Youarethenbroughtbacktotheloginscreen.
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

67

Sequentialcommands
Cantypethenextcommandinyourterminalevenwhenthe currentoneisnotover. Canseparatecommandswiththe;symbol: echoIlovethee;sleep10;echonot Conditionals:use||(or)or&&(and): moreGod||echoSorry,Goddoesn'texist Runsechoonlyifthefirstcommandfails ls~sd6&&cat~sd6/*>~sydney/recipes.txt Onlycatsthedirectorycontentsifthelscommandsucceeds (meansreadaccess).
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

68

Quoting(1)
Double(")quotescanbeusedtopreventtheshellfrominterpreting spacesasargumentseparators,aswellastopreventfilenamepattern expansion. >echo"HelloWorld" HelloWorld >echo"Youareloggedas$USER" Youareloggedasbgates >echo*.log find_prince_charming.logcosmetic_buys.log >echo"*.log" *.log
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

69

Quoting(2)
Singlequotesbringasimilarfunctionality,butwhatisbetween quotesisneversubstituted >echo'Youareloggedas$USER' Youareloggedas$USER Backquotes(`)canbeusedtocallacommandwithinanother >cd/lib/modules/`unamer`;pwd /lib/modules/2.6.91.6_FC2 Backquotescanbeusedwithindoublequotes >echo"YouareusingLinux`unamer`" YouareusingLinux2.6.91.6_FC2

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

70

Measuringelapsedtime
timefind_expensive_housingnear <...commandoutput...> real0m2.304s(actualelapsedtime) user0m0.449s(CPUtimerunningprogramcode) sys0m0.106s(CPUtimerunningsystemcalls) real=user+sys+waiting waiting=I/Owaitingtime+idletime(runningothertasks)

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

71

Environmentvariables
Shellslettheuserdefinevariables. Theycanbereusedinshellcommands. Convention:lowercasenames Youcanalsodefineenvironmentvariables:variables thatarealsovisiblewithinscriptsorexecutablescalled fromtheshell. Convention:uppercasenames. env Listsalldefinedenvironmentvariablesandtheirvalue.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

72

Shellvariablesexamples
Shellvariables(bash) projdir=/home/marshall/coolstuff lsla$projdir;cd$projdir Environmentvariables(bash) cd$HOME exportDEBUG=1 ./find_extraterrestrial_life (displaysdebuginformationifDEBUGisset)

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

73

Mainstandardenvironmentvariables
Usedbylotsofapplications!
LD_LIBRARY_PATH DISPLAY MANPATH PATH

Manualpagesearchpath Commandsearchpath
PRINTER SHELL TERM USER

Sharedlibrarysearchpath ScreenidtodisplayX (graphical)applicationson.


EDITOR HOME

Defaultprintername Currentshellname Currentterminaltype Currentusername

Defaulteditor(vi,emacs...) Currentuserhomedirectory
HOSTNAME

Nameofthelocalmachine

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

74

PATHenvironmentvariables
PATH Specifiestheshellsearchorderforcommands /home/acox/bin:/usr/local/bin:/usr/kerberos/bin :/usr/bin:/bin:/usr/X11R6/bin:/bin:/usr/bin LD_LIBRARY_PATH Specifiesthesharedlibrary(binarycodelibrariessharedby applications,liketheClibrary)searchorderforld /usr/local/lib:/usr/lib:/lib:/usr/X11R6/lib MANPATH Specifiesthesearchorderformanualpages /usr/local/man:/usr/share/man
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

75

PATHusagewarning
Itisstronglyrecommendednottohavethe.directoryinyourPATH environmentvariable,inparticularnotatthebeginning: Acrackercouldplaceamaliciouslsfileinyourdirectories.Itwould getexecutedwhenyourunlsinthisdirectoryandcoulddonaughty thingstoyourdata. Ifyouhaveanexecutablefilecalledtestinadirectory,thiswill overridethedefaulttestprogramandsomescriptswillstopworking properly. Eachtimeyoucdtoanewdirectory,theshellwillwastetimeupdating itslistofavailablecommands. Callyourlocalcommandsasfollows:./test

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

76

Alias
Shellsletyoudefinecommandaliases:shortcutsforcommandsyouuse veryfrequently. Examples
aliasls='lsla' Usefultoalwaysruncommandswithdefaultarguments. aliasrm='rmi' Usefultomakermalwaysaskforconfirmation. aliasfrd='find_rambaldi_deviceasaprisky' Usefultoreplaceverylongandfrequentcommands. aliascia='./home/sydney/env/cia.sh' Usefultosetanenvironmentinaquickway (.isashellcommandtoexecutethecontentofashellscript).

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

77

Thewhichcommand
Beforeyourunacommand,whichtellsyouwhereitisfound bash>whichls aliasls='lscolor=tty' /bin/ls tcsh>whichls ls:aliasedtolscolor=tty bash>whichalias /usr/bin/which:noaliasin (/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin) tcsh>whichalias alias:shellbuiltincommand.
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

78

~/.bashrcfile
~/.bashrc
Shellscriptreadeachtimeabashshellisstarted Youcanusethisfiletodefine
Yourdefaultenvironmentvariables(PATH,EDITOR...). Youraliases. Yourprompt(seethebashmanualfordetails). Agreetingmessage.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

79

Commandediting
Youcanusetheleftandrightarrowkeystomovethecursor inthecurrentcommand. Youcanuse[Ctrl][a]togotothebeginningoftheline, and[Ctrl][e]togototheend. Youcanusetheupanddownarrowstoselectearlier commands.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

80

Commandhistory(1)
history Displaysthelatestcommandsthatyouranandtheirnumber. Youcancopyandpastecommandstrings. Youcanrecallthelatestcommand: !! Youcanrecallacommandbyitsnumber !1003 Youcanrecallthelatestcommandmatchingastartingstring: !cat

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

81

Commandhistory(2)
Youcanmakesubstitutionsonthelatestcommand: ^more^less Youcanrunanothercommandwiththesamearguments: more!*

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

82

TheUnixandGNU/Linuxcommandline

Miscellaneous
Texteditors

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

83

Texteditors
Graphicaltexteditors Fineformostneeds nedit Emacs,Xemacs Textonlytexteditors Oftenneededforsysadminsandgreatforpowerusers vi nano

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

84

Thenedittexteditor
http://www.nedit.org/ Besttexteditorfornonvioremacsexperts Featurehighlights:
Veryeasytextselectionandmoving Syntaxhighlightingformostlanguagesandformats.Canbe tailoredforyourownlogfiles,tohighlightparticularerrors andwarnings. Easytocustomizethroughmenus

Notinstalledbydefaultbyalldistributions

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

85

neditscreenshot

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

86

Emacs/Xemacs
EmacsandXemacsareprettysimilar (uptoyourpreference) Extremelypowerfultexteditorfeatures Greatforpowerusers Lessergonomicthannedit Nonstandardshortcuts Muchmorethanatexteditor (games,email,shell,browser). Somepowercommandshavetobe learnt.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

87

vi
TextmodetexteditoravailableinallUnixsystems.Created beforecomputerswithmiceappeared. Difficulttolearnforbeginnersusedtographicaltexteditors. Veryproductiveforpowerusers. Oftencan'tbereplacedtoeditfilesinsystemadministration orinEmbeddedSystems,whenyoujusthaveatextconsole.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

88

vimviimproved
viimplementationnowfoundinmostGNU/Linux hostsystems Implementslotsoffeaturesavailableinmodern editors:syntaxhighlighting,commandhistory,help, unlimitedundoandmuchmuchmore. Coolfeatureexample:candirectlyopencompressed textfiles. ComeswithaGTKgraphicalinterface(gvim) Unfortunately,notfreesoftware(becauseofasmall restrictioninfreedomtomakechanges)

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

89

vibasiccommands
Thoughviisextremely powerful,itsmain30 commandsareeasytolearn andaresufficientfor99%of everyone'sneeds! Youcanalsotakethequick tutorialbyrunning vimtutor. Getourvimementosheetifyoudidn'tgetitwiththiscourse: http://freeelectrons.com/training/intro_unix_linux
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

90

GNUnano
http://www.nanoeditor.org/ Anothersmalltextonly,mousefreetexteditor. AnenhancedPicoclone(nonfreeeditorinPine) Friendlyandeasiertolearnforbeginnersthankstoonscreen commandsummaries. Availableinbinarypackagesforseveralplatforms. Analternativetoviinembeddedsystems. However,notavailableasabusyboxbuiltin.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

91

GNUnanoscreenshot

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

92

TheUnixandGNU/Linuxcommandline

Compressingandarchiving

Miscellaneous

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

93

Measuringdiscusage
Caution:differentfromfilesize! duh<file>(diskusage) h:returnssizeondiskofthegivenfile,inhumanreadable format:K(kilobytes),M(megabytes)orG(gigabytes),. Withouth,dureturnstherawnumberofdiskblocksused bythefile(hardtoread). NotethatthehoptiononlyexistsinGNUdu. dush<dir> s:returnsthesumofdiskusageofallthefilesinthegiven directory.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

94

Measuringdiskspace
dfh<dir> Returnsdiskusageandfreespaceforthefilesystemcontaining thegivendirectory. Similarly,thehoptiononlyexistsinGNUdf. Example:
>dfh. FilesystemSizeUsedAvailUse%Mountedon /dev/hda59.2G7.1G1.8G81%/

dfh Returnsdiskspaceinformationforallfilesystemsavailablein thesystem.Whenerrorshappen,usefultolookforfull filesystems.


TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

95

Compressing
Veryusefulforshrinkinghugefilesandsavingspace g[un]zip<file> GNUzipcompressionutility.Creates.gzfiles. Ordinaryperformance(similartoZip). b[un]zip2<file> Morerecentandeffectivecompressionutility. Creates.bz2files.Usually2025%betterthangzip. Using7zip Muchbettercompressionratiothanbzip2(upto10to20%). Seethe7zippagefordetails.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

96

Archiving(1)
Usefultobackuporreleaseasetoffileswithin1file tar:originallytapearchive Creatinganarchive: tarcvf<archive><filesordirectories> c:create v:verbose.Usefultofollowarchivingprogress. f:file.Archivecreatedinfile(tapeusedotherwise). Example: tarcvf/backup/home.tar/home bzip2/backup/home.tar

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

97

Archiving(2)
Viewingthecontentsofanarchiveorintegritycheck: tartvf<archive> t:test Extractingallthefilesfromanarchive: tarxvf<archive> Extractingjustafewfilesfromanarchive: tarxvf<archive><filesordirectories> Filesordirectoriesaregivenwithpathsrelativetothe archiverootdirectory.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

98

ExtraoptionsinGNUtar
tar=gtar=GNUtaronGNU/Linux Cancompressanduncompressarchivesonthefly.Usefulto avoidcreatinghugeintermediatefiles Muchsimplertodothanwithtarandbzip2! joption:[un]compressesontheflywithbzip2 zoption:[un]compressesontheflywithgzip Examples(whichonewillyouremember?)
gtarjcvfbills_bugs.tar.bz2bills_bugs tarcvfbills_bugs|bzip2>bills_bugs.tar.bz2

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

99

7zip(1)
http://www.7zip.org/ Nowthebestsolutionforyourarchives! License:GNULGPL 7zipcompressesmuchbetterthanbzip2(upto10or20%) andofcoursezip(30to50%). BenchmarkcompressingKnoppix5.0.1:22%(vs.bzip2)! Caution:7zipcannotreplacetarforarchivingonUnix. Itdoesn'tkeepfileownerandgroupinformation, butofcoursekeepsfilepermissions. Useittocompresstararchives!

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

100

7zip(2)
7zipsupportsstrongAES256encryption. Noneedtoencryptinaseparatepass. AtlastasolutionavailableforUnixandWindows! Thetoolsupportsmostothercompressionformats: zip,cab,arj,gzip,bzip2,tar,cpio,rpmanddeb.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

101

Using7zip
Archivefilesareusuallycreatedwitha.7zextension Creatinganarchive:(a:add) 7za<archive><filesordirectories> Listfilesinarchive:(l:list) 7zl<archive> Extractingfroma7ziparchive:(e:extract) 7zx<archive> Backupadirectory(keepingownerandgroupinformation): tarcf<dir>|7zasidir.tar.7z Restorethisbackup: 7zxsodir.tar.7z|tarxf
standardoutput
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

standardinput

102

Checkingfileintegrity
Verylowcostsolutiontocheckfileintegrity md5sumFC3i386disk*.iso>MD5SUM ComputesaMD5(MessageDigestAlgorithm5)128bitchecksumofthe givenfiles.Usuallyredirectedtoafile. Exampleoutput: db8c7254beeb4f6b891d1ed3f689b412FC3i386disc1.iso 2c11674cf429fe570445afd9d5ff564eFC3i386disc2.iso f88f6ab5947ca41f3cf31db04487279bFC3i386disc3.iso 6331c00aa3e8c088cc365eeb7ef230eaFC3i386disc4.iso md5sumcMD5SUM CheckstheintegrityofthefilesinMD5SUMbycomparingtheiractualMD5 checksumwiththeiroriginalone.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

103

TheUnixandGNU/Linuxcommandline

Miscellaneous
Printing

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

104

Unixprinting
Multiuser,multijob,multiclient,multiprinter InUnix/Linux,printingcommandsdon'treallyprint.Theysendjobs toprintingqueues,possiblyonthelocalmachine,onnetworkprinting serversoronnetworkprinters. Printerindependentsystem: PrintserversonlyacceptjobsinPostScript ortext.Printerdriversontheservertake careoftheconversiontoeachprintersownformat. Robustsystem: Rebootasystem,itwillcontinuetoprintpendingjobs.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

105

Printingcommands
Usefulenvironmentvariable:PRINTER Setsthedefaultprinteronthesystem.Example: exportPRINTER=lp lpr[P<queue>]<files> Sendsthegivenfilestothespecifiedprintingqueue ThefilesmustbeintextorPostScriptformat.Otherwise,youonly printgarbage. a2ps[P<queue>]<files> AnytoPostScriptconvertsmanyformatstoPostScriptandsend theoutputtothespecifiedqueue.Usefulfeatures:severalpages/ sheet,pagenumbering,infoframe...

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

106

Printjobcontrol
lpq[P<queue>] Listsalltheprintjobsinthegivenordefaultqueue.
lpisnotready RankOwnerJobFile(s)TotalSize 1stasloane84nsa_windows_backdoors.ps60416bytes 2ndamoore85gw_bush_iraq_mistakes.ps65024000bytes

cancel<job#>[<queue>] Removesthegivenjobnumberfromthedefaultqueue.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

107

UsingPostScriptandPDFfiles
ViewingaPostScriptfile PostScriptviewersexist,buttheirqualityisprettypoor. BetterconverttoPDFwithps2pdf: ps2pdfdecss_algorithm.ps xpdfdecss_algorithm.pdf& PrintingaPDFfile Youdon'tneedtoopenaPDFreader! BetterconverttoPostScriptwithpdf2ps: pdf2psrambaldi_artifacts_for_dummies.pdf lprrambaldi_artifacts_for_dummies.ps

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

108

TheUnixandGNU/Linuxcommandline

Comparingfilesanddirectories

Miscellaneous

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

109

Comparingfilesanddirectories
difffile1file2 Reportsthedifferencesbetween2files,ornothingifthefiles areidentical. diffrdir1/dir2/ Reportsallthedifferencesbetweenfileswiththesamenamein the2directories. Toinvestigatedifferencesindetail,betterusegraphicaltools!

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

110

tkdiff
http://tkdiff.sourceforge.net/ Usefultooltocomparefilesandmergedifferences

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

111

kompare
Anothernicetooltocomparefilesandmergedifferences Partofthekdesdkpackage(FedoraCore)

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

112

gvimdiff
Anothernicetooltoviewdifferencesinfiles
Availableinmost distributionswithgvim Apparentlynotusing diff. Noissuewithfileswith binarysections!

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

113

TheUnixandGNU/Linuxcommandline

Lookingforfiles

Miscellaneous

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

114

Thefindcommand
Betterexplainedbyafewexamples! find.name*.pdf Listsallthe*.pdffilesinthecurrent(.)directoryor subdirectories.Youneedthedoublequotestopreventtheshell fromexpandingthe*character. finddocsname"*.pdf"execxpdf{}';' Findsallthe*.pdffilesinthedocsdirectoryanddisplays oneaftertheother. Manymorepossibilitiesavailable!However,theabove2 examplescovermostneeds.
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

115

Thelocatecommand
Muchfasterregularexpressionsearchalternativetofind locatekeys Listsallthefilesonyoursystemwithkeysintheirname. locate*.pdf Listsallthe*.pdffilesavailableonthewholemachine locate/home/fridge/*beer* Listsallthe*beer*filesinthegivendirectory(absolutepath) locateismuchfasterbecauseitindexesallfilesinadedicated database,whichisupdatedonaregularbasis. findisbettertosearchthroughrecentlycreatedfiles.
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

116

TheUnixandGNU/Linuxcommandline

Variouscommands

Miscellaneous

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

117

Gettinginformationaboutusers
who Listsalltheusersloggedonthesystem. whoami TellswhatuserIamloggedas. groups TellswhichgroupsIbelongto. groups<user> Tellswhichgroups<user>belongsto. finger<user> Tellsmoredetails(realname,etc)about<user> Disabledinsomesystems(securityreasons).
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

118

Changingusers
Youdonothavetologouttologonanotheruseraccount! suhyde (Rare)Changetothehydeaccount,butkeepingthe environmentvariablesettingsoftheoriginaluser. sujekyll (Morefrequent)Logonthejekyllaccount,withexactly thesamesettingsasthisnewuser. su Whennoargumentisgiven,itmeanstherootuser.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

119

Thewgetcommand
Insteadofdownloadingfilesfromyourbrowser,justcopyandpaste theirURLanddownloadthemwithwget! wgetmainfeatures httpandftpsupport Canresumeinterrupteddownloads Candownloadentiresitesoratleastcheckforbadlinks Veryusefulinscriptsorwhennographicsareavailable (systemadministration,embeddedsystems) Proxysupport(http_proxyandftp_proxyenv.variables)

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

120

wgetexamples
wgetc\ http://microsoft.com/customers/dogs/winxp4dogs.zip Continuesaninterrupteddownload. wgetmhttp://lwn.net/ Mirrorsasite. wgetrnphttp://www.xml.com/ldd/chapter/book/ Recursivelydownloadsanonlinebookforofflineaccess. np:"noparent".Onlyfollowslinksinthecurrentdirectory.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

121

Misccommands(1)
sleep60 Waitsfor60seconds (doesn'tconsumesystemresources). wcreport.txt(wordcount) 438211518302report.txt Countsthenumberoflines,wordsandcharactersina fileorinstandardinput.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

122

Misccommands(2)
bc("basiccalculator?") bcisahandybutfullfeaturedcalculator.Evenincludes aprogramminglanguage!Usetheloptiontohave floatingpointsupport. date Returnsthecurrentdate.Usefulinscriptstorecordwhen commandsstartedorcompleted.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

123

TheUnixandGNU/Linuxcommandline

Systemadministrationbasics

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

124

Fileownership
chownRsco/home/linux/src(R:recursive) Makesuserscothenewownerofallthefilesin /home/linux/src. chgrpRempire/home/askywalker Makesempirethenewgroupofeverythingin /home/askywalker. chownRborg:aliensusss_entreprise/ chowncanbeusedtochangetheownerandgroupatthe sametime.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

125

Shuttingdown
shutdownh+5(h:halt) Shutsthesystemdownin5minutes. Usersgetawarningintheirconsoles. shutdownrnow(r:reboot) init0 Anotherwaytoshutdown(usedbyshutdown). init6 Anotherwaytoreboot(usedbyshutdown). [Ctrl][Alt][Del] AlsoworksonGNU/Linux(atleastonPCs!).
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

126

Networksetup(1)
ifconfiga Printsdetailsaboutallthenetworkinterfacesavailable onyoursystem. ifconfigeth0 Listsdetailsabouttheeth0interface ifconfigeth0192.168.0.100 Assignsthe192.168.0.100IPaddress toeth0(1IPaddressperinterface). ifconfigeth0down Shutsdowntheeth0interface (freesitsIPaddress).

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

127

Networksetup(2)
routeadddefaultgw192.168.0.1 Setsthedefaultrouteforpacketsoutsidethelocalnetwork. Thegateway(here192.168.0.1)isresponsiblefor sendingthemtothenextgateway,etc.,untilthefinal destination. route Liststheexistingroutes routedeldefault routedel<IP> Deletesthegivenroute Usefultoredefineanewroute.
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

128

Networktesting
pingfreshmeat.net ping192.168.1.1 Triestosendpacketstothegivenmachineandgetacknowledgment packetsinreturn.
PING192.168.1.1(192.168.1.1)56(84)bytesofdata. 64bytesfrom192.168.1.1:icmp_seq=0ttl=150time=2.51ms 64bytesfrom192.168.1.1:icmp_seq=1ttl=150time=3.16ms 64bytesfrom192.168.1.1:icmp_seq=2ttl=150time=2.71ms 64bytesfrom192.168.1.1:icmp_seq=3ttl=150time=2.67ms

Whenyoucanpingyourgateway,yournetworkinterfaceworksfine. WhenyoucanpinganexternalIPaddress,yournetworksettingsare correct!


TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

129

Networksetupsummary
Onlyforsimplecaseswith1interface,nodhcpserver... Connecttothenetwork(cable,wirelesscardordevice...) Identifyyournetworkinterface: ifconfiga AssignanIPaddresstoyourinterface(assumingeth0) ifconfigeth0192.168.0.100(example) Addaroutetoyourgateway(assuming192.168.0.1)for packetsoutsidethenetwork: routeadddefaultgw192.168.0.1

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

130

Nameresolution
YourprogramsneedtoknowwhatIPaddresscorrespondstoa givenhostname(suchaskernel.org) DomainNameServers(DNS)takecareofthis. YoujusthavetospecifytheIPaddressof1ormoreDNS serversinyour/etc/resolv.conffile: nameserver217.19.192.132 nameserver212.27.32.177 Thechangestakeseffectimmediately!

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

131

Creatingfilesystems
Examples mkfs.ext2/dev/sda1 FormatsyourUSBkey(/dev/sda1:1stpartitionrawdata)inext2format. mkfs.ext2Fdisk.img Formatsadiskimagefileinext2format mkfs.vfatvF32/dev/sda1(v:verbose) FormatsyourUSBkeybacktoFAT32format. mkfs.vfatvF32disk.img FormatsadiskimagefileinFAT32format. Blankdiskimagescanbecreatedainthebelowexample: ddif=/dev/zeroof=disk.imgbs=1024count=65536

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

132

Mountingdevices(1)
Tomakefilesystemsonanydevice(internalorexternalstorage) visibleonyoursystem,youhavetomountthem. Thefirsttime,createamountpointinyoursystem: mkdir/mnt/usbdisk(example) Now,mountit: mounttvfat/dev/sda1/mnt/usbdisk /dev/sda1:physicaldevice t:specifiesthefilesystem(format)type (ext2,ext3,vfat,reiserfs,iso9660...)

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

133

Mountingdevices(2)
Lotsofmountoptionsareavailable,inparticulartochoosepermissionsorthe fileownerandgroup...Seethemountmanualpagefordetails. Mountoptionsforeachdevicecanbestoredinthe/etc/fstabfile. Youcanalsomountafilesystemimagestoredinaregularfile(loopback devices) UsefultoaccessthecontentsofanISOcdromimagewithouthavingto burnit. UsefultocreateaLinuxpartitiononaharddiskwithonlyWindows partitions cp/dev/sda1usbkey.img mountolooptvfatusbkey.img/mnt/usbdisk

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

134

Listingmountedfilesystems
Justusethemountcommandwithnoargument:
/dev/hda6on/typeext3(rw,noatime) noneon/proctypeproc(rw,noatime) noneon/systypesysfs(rw) noneon/dev/ptstypedevpts(rw,gid=5,mode=620) usbfson/proc/bus/usbtypeusbfs(rw) /dev/hda4on/datatypeext3(rw,noatime) noneon/dev/shmtypetmpfs(rw) /dev/hda1on/wintypevfat(rw,uid=501,gid=501) noneon/proc/sys/fs/binfmt_misctypebinfmt_misc(rw)

Ordisplaythe/etc/mtabfile (sameresult,updatedbymountandumounteachtimetheyarerun)

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

135

Unmountingdevices
umount/mnt/usbdisk Commitsallpendingwritesandunmountsthegivendevice, whichcanthenberemovedinasafeway. Tobeabletounmountadevice,youhavetocloseallthe openfilesinit:
Closeapplicationsopeningdatainthemountedpartition Makesurethatnoneofyourshellshaveaworkingdirectoryin thismountpoint. Youcanrunthelsofcommand(listopenfiles)toview whichprocessesstillhaveopenfilesinthemountedpartition.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

136

TheUnixandGNU/Linuxcommandline

GNU/Linux:distributionpackages

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

137

Howtofindpackages
Debianpackages:http://www.debian.org/distrib/packages Searchbypackageorfilename rpmfind:http://rpmfind.net/ LotsofRPMpackagesforRedHat,Mandriva,Suse...

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

138

Identifyingpackages
Whatpackagedoesafilebelongto? Usefultogetmoreinformation,getthecode,findnewer versions,reportissues... DistributionwithRPMpackages: (RedHat,Fedora,Mandriva,Suse...) >rpmqf/bin/ls coreutils5.2.17 Debian: >dpkgS/bin/ls fileutils:/bin/ls
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

139

Informationaboutpackages
Accesspackagedescription,versionnumber,sources,etc. RPMbaseddistributions: rpmqi<packagename> Debian: dpkgs<packagename>

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

140

TheUnixandGNU/Linuxcommandline

Goingfurther

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

141

Commandhelp
SomeUnixcommandsandmostGNU/Linuxcommandsoffer atleastonehelpargument: h (ismostlyusedtointroduce1characteroptions) help (isalwaysusedtointroducethecorrespondinglong optionname,whichmakesscriptseasiertounderstand) Youalsooftengetashortsummaryofoptionswhenyouinput aninvalidargument.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

142

Manualpages
man<keyword> Displaysoneorseveralmanualpagesfor<keyword> manman MostavailablemanualpagesareaboutUnixcommands,butsome arealsoaboutCfunctions,headersordatastructures,orevenabout systemconfigurationfiles! manstdio.h manfstab(for/etc/fstab) Manualpagefilesarelookedforinthedirectoriesspecifiedbythe MANPATHenvironmentvariable.
TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

143

Infopages
InGNU,manpagesarebeingreplacedbyinfopages.Some manualpageseventelltorefertoinfopagesinstead. info<command> infofeatures:
Documentationstructuredinsections(nodes)andsubsections (subnodes) Possibilitytonavigateinthisstructure:top,next,prev,up InfopagesgeneratedfromthesametexinfosourceastheHTML documentationpages

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

144

SearchingtheInternetforresources(1)
Investigatingissues Mostforumsandmailinglistarchivesarepublic,andare indexedonaveryfrequentbasisbyGoogle. Ifyouinvestigateanerrormessage,copyitverbatiminthe searchform,enclosedindoublequotes(errormessage).Lots ofchancesthatsomebodyelsealreadyfacedthesameissue. Don'tforgettouseGoogleGroups:http://groups.google.com/ Thissiteindexesmorethan20yearsofnewsgroupsmessages.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

145

SearchingtheInternetforresources(2)
Lookingfordocumentation
Lookfor<tool>or<tool>pagetofindthetoolorproject homepageandthenfindthelatestdocumentationresources. Lookfor<tool>documentationor<tool>manualin yourfavoritesearchengine.

Lookingforgenerictechnicalinformation
WikiPedia:http://wikipedia.org Lotsofusefuldefinitionsincomputerscience.Areal encyclopedia!Opentoanyone'scontributions.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

146

Traininglabs
Traininglabsarealsoavailablefromthesamelocation: http://freeelectrons.com/training/intro_unix_linux Theyareausefulcomplementtoconsolidate whatyoulearnedfromthistraining.Theydon'ttell howtodotheexercises.However,theyonlyrely onnotionsandtoolsintroducedbythelectures. Ifyouhappentobestuckwithanexercise,thisprovesthatyoumissed somethinginthelecturesandhavetogobacktotheslidestofindwhat you'relookingfor.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

147

Relateddocuments
Thisdocumentbelongstothemorethan1000pagematerialsofanembeddedGNU/ LinuxtrainingfromFreeElectrons,availableunderafreedocumentationlicense. http://freeelectrons.com/training
IntroductiontoUnixandGNU/Linux EmbeddedLinuxkernelanddriverdevelopment FreeSoftwaretoolsforembeddedLinuxsystems AudioinembeddedLinuxsystems MultimediainembeddedLinuxsystems LinuxonTIOMAPprocessors FreeSoftwaredevelopmenttools IntroductiontouClinux RealtimeinembeddedLinuxsystems What'snewinLinux2.6? JavainembeddedLinuxsystems HowtoportLinuxonanewPDA

http://freeelectrons.com/articles
EmbeddedLinuxoptimizations EmbeddedLinuxfromScratch...in40min!

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

148

Howtohelp
Ifyousupportthiswork,youcanhelp... Bysendingcorrections,suggestions,contributionsandtranslations Byaskingyourorganizationtoordertrainingsessionsperformedby theauthorofthesedocuments(seehttp://freeelectrons.com/training) Byspeakingaboutittoyourfriends,colleagues andlocalFreeSoftwarecommunity. Byaddinglinkstoouronlinematerialsonyourwebsite, toincreasetheirvisibilityinsearchengineresults.

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

149

Thanks
TotheOpenOffice.orgproject,fortheirpresentationand wordprocessortoolswhichsatisfiedallmyneeds. TotheHandhelds.orgcommunity,forgivingmesomuch helpandsomanyopportunitiestohelp. TothemembersofthewholeFreeSoftwareandOpen Sourcecommunity,forsharingthebestofthemselves:their work,theirknowledge,theirfriendship. Topeoplewhosentcommentsandcorrections: LaurentThomas,JeffGhislain,LeifThande,Frdric Desmoulins,PrzemysawCiesielski

TheUnixandGNU/Linuxcommandline Copyright20062004,MichaelOpdenacker CreativeCommonsAttributionShareAlike2.0license http://freeelectrons.com Aug31,2006

150

EmbeddedLinuxTraining UnixandGNU/Linuxbasics Linuxkernelanddriversdevelopment RealtimeLinux uClinux Developmentandprofilingtools Lightweighttoolsforembeddedsystems Rootfilesystemcreation Audioandmultimedia Systemoptimization

FreeElectronsservices
CustomDevelopment Systemintegration EmbeddedLinuxdemosandprototypes Systemoptimization Linuxkerneldrivers Applicationandinterfacedevelopment

Consulting Helpindecisionmaking Systemarchitecture Identificationofsuitabletechnologies Managinglicensingrequirements Systemdesignandperformancereview

TechnicalSupport Developmenttoolandapplicationsupport Issueinvestigationandsolutionfollowupwith mainstreamdevelopers Helpgettingstarted

http://freeelectrons.com

You might also like