Unix Basics

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

c shell is better than bourne shell.

It allows aliasing of commands. It has command history.

grepglobalregularexpressionprint:Itisatextsearchutilityavailbleinunix. command:grepapplefruitlist.txt Inthiscase,grepprintsalllinescontainingapplefromthefilefruitlist.txt,regardlessof wordboundaries;thereforelinescontainingpineappleorapplesarealsoprinted.Thegrep commandiscasesensitivebydefault,sothisexample'soutputdoesnotincludelinescontaining Apple(withacapitalA)unlesstheyalsocontainapple.

grep^a.plefruitlist.txt grepiapplefruitlist.txtthisprintsalllinescontainingappleregardlessofcapitalization. Theiargumenttellsgreptobecaseinsensitive,ortoignorecase.

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

file2isnotexistthenitcreateit) Toconcatenatethecontentoftwofileintoasingleone. cattesttest1>new thiscommandconcatenatethecontentoftestandtest1intoasinglefilenew.Butif newalreadycontainssomethingitisoverwritten...Toappendituse>>

Unixdoesnthavestringent3characterextensionrule. Removingafileusingcommand rmifile;whereiisaswitchremovefileinteractively fordirectoryuses rmrdir1thiscommandrecursivelyremovesallcontentsofdir1andalsodir1 itself. rmfdir1(fmeansforciblyirrespectiveofpermissions)

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.

Cutcommand o Cutf2,7empinfo o Cutf27empinfo o Cutf2,7d:empinfo

(viewonlyfield2and7) (viewthrough2to7) (ddelimeter)

Filecompressiondependsonfiledonebycommandcompressandpack o Compressv(verbose)trial.txt.Itchangethefilefromtrial.txt.z o Uncompresstrail.txt.z o Toseecontentoftrial.txt.zuse Zcattrial.txt.z

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.

Proxy settings in ubuntu 10.10


o If youre using command-line apt-get.Edit your /etc/bash.bashrc file as root.Put these line at the end of your /etc/bash.bashrc file :
export http_proxy=http://username:password@proxyserver.net:port/ export ftp_proxy=http://username:password@proxyserver.netport/

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/

You might also like