Professional Documents
Culture Documents
Unix Basics
Unix Basics
Unix Basics
propertiesofunixfilesystem:
(a)Ithashierarchicalfilestructure. (b)Filescangrowdynamically. (c)Filehaveaccesspermissions. (d)Alldeviceareimplementedasfiles. BasicCommands touchandcatusedtocreateafile.Howeversizeofdisfileiszerobytes.Sincetouchdoes notallowyoutostoreanythinginafile.catisusedtoputsomethinginit. Tocreateafile
Howeverusingtouchucanmodifythemodificationtimeaswellasaccesstimeofafile. Command:Tochangeaccesstime touchamyfile;Toseeituselsl Tochangethemodificationtimetouchmmyfile cat>test hellodear......denpressctrl+d Toviewthecontentofafile cattestpressEnter catfile1>file2 (itredirectstheoutputoffile1tofile2,insteadgettingonterminal.If
forrenamedirectoryinunixweusemvcommand. $mvtestsample FILErelatedcommand filecommandlistalldirectoryaswellasfilealsowhetheremptyornot. Wcl,c,w. Sortisusedtosortthefileusingfirstspace,tabs,punctuationmarks,number,Uppercase, Lowercaselettersi.e.ASCIIcollatingsequence. o Sortfile1file2file3 o Sortoresultfile1file2file3(tostoretheresultantsortedfileinoresultfile) o Sortuoresultfile1file2file3(torepresentuniquely) o Sortmfile1file2 (tomergethealreadysortedfile) o Sortfile1 (heremeanskeyboard,usewheninputaddedfrm keyboardthencarryoutsorting) o Sort (inputfrmkeyboard) o Assumefilestudenthas4fieldsforrollnum,name,marksi.e.numbered0,1,2,3. Thensortbasisonnameas Sortr+12student,wecanevenhavemultiplesortkey rindicatesreversesort. Note:bignoringleadingspaceandtabs. ccheckfilearealreadysortedifalreadysortedthendonothing dsortindictionaryorder +n[m]skipsnfiledbeforesortingandthensortthroughfieldm.
i/oredirectionandpiping >operatormeansdonotdisplayoutputonscreeninsteadputitsomewhereelse(fileor printer) <operatormeansdonottakeinputfromkeyboardinsteadlookitsomewhereelse(fileor keyboard) Anycommandthatacceptstandardinputalsoacceptsinputredirection.Eg.Catas: o Cat<newfile (newfileisstandardinput) Hellodudehowareyou $Catnewfile (firstinputisnewfileandsecondinputiskeyboard.)
$cat<currentfile>newfilesameas$cat>newfile<currentfile itmeansthat<currentfile,indicatesthatinputtakenfromfilecurrentfile,andsecondpart ofredirection>newfileestablishoutputroutedtofilenewfile.Orderinwhichthesetwoare useddoesntmatter. Piping:$ls|wcl>countfileinthisoutputoflsbecomesinputtowcwhichpromptly countsnumberoflinesitreceivesasinputandredirecttofilenamedcountfile. Nowinputfrompipecanbecombinedtoinputfromfiles.Forthisusehyphen()forthose commandthatrecognisehyphenasstandardinputeg. $who|sortlogfile>newfile Todobothpiping(routesoutputtootherprograms)andredirection(routeso/ptofile)unix providesteecommandtodoso. $who|teelogfilenewlogfile|sort (o/pofwhoreceivebyteewhichnowsendone copytosortthroughpipelinewhereasothercopystoredinlogfileandnewlogfile) $who|teefile1file2/dev/tty3a|sort>file3 $catfile1file2|teeanewlogfile|more (ameansappend) $catmyfile>newfile2>errorfile Processinunix $psitdisplaystherunningprocesscurrentlyinmemoryaturterminal.formoredetails
use$psa.(forotheruserswhohaveloogedin) o forspecificuseruse:$psuuser1 o forparticularterminaluse:$psttty3d. o formoreinfruse:$psf o stillmorei.eforevery(e)processrunningatthatinstant:pse o schedisscheduleritspid=0;itgivesbirthinitializeprocess/etc/initsopid=1and ppid=0;vhandisvirtualmemoryhandleritcutsoutforitsswapactiveprocesses betweenmemoryanddiskastheyrunorwaittheirturninqueuetobeprocessedby systemanditisinitiatedbyinitsopid=2;bdflushbuffertodiskflush o vhand,bdflushandschedarehousedinkernelfile/sopopularlycalleddaemons. Torunaprocessinabackgroundunixprovides&symbol. Sortemployee.dat>emp.dat& 17645denotedpid Nohupcommandmeansnohangupi.e.backgroundprocessdonotdieevenwhenwelogout nohupsortemployee.dat>output.emp o Evenifwenotredirecttheoutputitintelligentlyredirecttonohup.outitalways createdincrrntwrkgdirectory. o Note:inpipingcaseusenohupineachcommand Killingaprocess o Tokillaprocessweneedtoknowitspidthenuse$killpid.killingaprocessmeans creatingasignalthatforceittoterminateit.Eachsignalaccomplishedbyanumber. Ifwedonotprovideanynumberdefaultisprovided. o Notallprocessiskilledbydefaultsignalnumber.Toforciblykillweuse kill9pid. o Systemprocesscannotkilled. Changingprocesspriorities o Eachprocesshasitsnicevaluewhichindicatesispriority.Itrangesin039.By defaultis20.highertheniceloweritspriority.
o In terminal, type command $sudo gedit /etc/apt/apt.conf then add lines as:
exporthttp_proxy=http://username:password@proxyserver.net:port/ export ftp_proxy=http://username:password@proxyserver.netport/