Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction
ManypeoplesaysthatLinuxisacommandbased operatingsystem. SomanyofusthinksthatLinuxisnotsouserfriendly OS. Butitisnottrue.LinuxisaGUIbasedOSwithaShell whichismorepowerfulthanitscounterpartinWindows OS. Wewillbefamiliarwithsomeshellcommands.
Identity
Manual
ForeachcommandLinuxcontainsmanual.Toviewthe manual:manname
manuname
Editors
Toviewfilesalargenumberofeditorsareavailable. Theyare: kwrite emacs gedit vi Toview:editornamefilename kwritefile.txt
User
ViewText
Toviewalineoftextintheshell:echo echowelcometolinux Tocleartheshell:clear
DirectoryandFilePermissions
Eachfileordirectoryhas3securitygroups. Owner Group AllOthers Eachsecuritygrouphas3flagsthatcontroltheaccess status:read,write,execute Theyarelistedas'rwx'ora""iftheaccessisturnedoff. rwxrwxrwx [read,writeandexecutableforowner, groupandallothers] rwrr [readandwritebyowner,readonlyfor groupandallothers]
DirectoryandFilePermissions
Tochangethepermissionstypechmod u,g,oorall[whosepermissionyouarechanging] +or [typeofchange:addorsubtractpermission] combinationofr,worx[whichpermissionyouare changing:read,writeorexecute] fileordirectory[nameoffileordirectorytochange] chmodgo+rwfile1file2addreadandwrite accessforgroupandothersforfiles'file1'and 'file2 chmoda+rwxfile1addread,writeandexecute foreveryonefor'file1. chmod555file1
DirectoryandFilePermissions
DirectoryandFileListings
DirectoryOperations
Toprintthecurrentdirectory:pwd Tochangethecurrentdirectory:cddirname ThevariableHOMEisthedefaultdirectory. Tomakeanewdirectory:mkdir m[setpermissionmode(asinchmod)] v[printamessageforeachcreateddirectory Todeleteanemptydirectory:rmdir
DirectoryOperations
Tomovetoadirectorypushingthecurrentdirectoryto stack:pushddirname Effect: addsadirectorytothetopofthedirectorystack orrotatesthestackmakingthenewtopofthestack thecurrentworkingdirectory
DirectoryOperations
Tomovestothedirectoryatthetopofthestackaswell astoremovethetopmostentry:popd Effect: removesthetopdirectoryfromthestack performsacd tothenewtopdirectory.
DirectoryOperations
Todisplaythelistofcurrentlyremembereddirectories: dirs Thedefaultdisplayisonasinglelinewithdirectory namesseparatedbyspaces. Howtoaddtothelist:pushd Howtoremovefromthelist:popd
FileOperations
FileOperations
FileOperations
FileOperations
Todeterminefiletype:file filename Filetestseachargumentinanattempttoclassifyit.This causesthefiletypetobeprinted i [showthemimetype]. v [Printtheversionofthefile] filea.txt:a.txt:veryshortfile filea.xls:a.xls:MicrosoftOfficeDocument filei a.xls:a.xls:\012 application/msword
FileOperations
FileViewing
Toviewfilesinshelluse:more orless. morefilename lessfilename Themaindifferencebetweenmoreandlessisthat lessallowsbackwardandforwardmovementusing thearrowkeys. moreonlyusesthe[Spacebar]andthe[B]keyfor forwardandbackwardnavigation.
FileViewing
FileViewing
FileViewing
FileViewing
Toprintthenumberoflines,wordsandbytesinfiles: wcfile1file2file3 printbyte,word,andnewlinecountsforeachfileanda totallineifmorethanonefileisspecified. l [printthenewlinecounts] w [printthewordcounts]
StandardI/O/E
Bydefault,threedefaultfilesknownasstandardfiles areautomaticallyopenedwhenacommandisexecuted. Theyarestandardinput(stdin),standardoutput (stdout)andstandarderror(stderr). Forexample,thecommandlsa scansthecurrent directoryandcollectsalistofallthefiles,producesa humanreadablelist,andoutputstheresulttothe terminalwindow.
Redirection
Linuxredirectionfeaturescanbeusedtodetachthe defaultfilesfromstdin,stdout andstderr andattach otherfilestothem. Inputredirection: < getinputfromfileinsteadofthekeyboard Outputredirection: > sendoutputtofileinsteadoftheterminal window Appendoutput: >> commandisusedtoappendtoafileifitalready exists
Piping
Theinputofacommandmaycomefromtheoutputof anothercommand. Thisisaccomplishedwiththe| pipeoperator.
Howtoviewthelines1520ofafilenameda.txt?
Piping
Theinputofacommandmaycomefromtheoutputof anothercommand. Thisisaccomplishedwiththe| pipeoperator.
Howtoviewthelines1520ofafilenameda.txt? head20a.txt|tail5
Grep
grepmatchesapatterninagivenalistoffilesor standardinputandoutputsonlythematchinglines. grep patternfilename grepabcfile.txt greppatternsarecasesensitivebydefault. Someoptions i [caseinsensitivesearch] c [countoftotalmatches] E [regularexpressionscanbeprovidedaspatterns] n [displaythelinenumbersofthematchedlines]
Find
searchforfilesinadirectoryhierarchy. Bydefault,findreturnsallfilesbelowthecurrent workingdirectory. find Tosearchapattern:findname'*txt*' Tosearchforafiletype: findtyped[findalldirectories] finetypef[findallregularfiles] Findexecutesthe'print'actionbydefault.Tochangeit tostylesuchasls:findtypefls
Find
Tosearchallthedirectories notrecommended find/name"myfile"typef Tosearchaspecificdirectory find/home/dir1name"myfile"typef Tosearchmultipledirectories finddir1dir2name"myfile"typef ToSearchforallfilesownedbyauser finduseruserid Totakeanaction findtypefname'*ch*'execchmoda+rwx{}\; {} isreplacedwiththenameofthefile The; indiatestheendofthecommand.
Thanks