0% found this document useful (0 votes)
125 views3 pages

Linux Shell Commands

This document provides examples of common Linux shell commands like grep, cat, sed, tr, cut, awk, and sort. It explains what each command does and provides 2-3 simple examples of using the commands in the shell or in scripts. The intention is to give a basic overview of these commands for scripting and using the Linux command line.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views3 pages

Linux Shell Commands

This document provides examples of common Linux shell commands like grep, cat, sed, tr, cut, awk, and sort. It explains what each command does and provides 2-3 simple examples of using the commands in the shell or in scripts. The intention is to give a basic overview of these commands for scripting and using the Linux command line.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

OverviewofaFewCommonCommands

PeteNesbitt May2006

LinuxShellCommands

BelowareafewexamplesofLinuxcommandsoftenseeninscripts.Ofcoursetheymaybe incorporatedintoscriptsorusedatthecommandline.Theintentionistoprovideabasicexampleof thesecommands,youmayfindthemanpage,thecommandfollowedbyhelporgoogleusefulfor furtheringyourunderstanding.Theyarepresentedinnoparticularorder. Althoughthesecommandsmayappearsimpleinfunction,mosthavemanyoptions.Therealpowerof scriptingorcomplexcommandlinescomeswhenthesesimplefunctionsarejoinedwithpipesand redirectswhichcancausetheoutputfromonecommandtobecometheinputofthenext.Inmostcases spaceshavebeenaddedaroundthepipesymbol'|',thisisforreadability.Suchspacesareoptionaland donotimpactthecommandstring. IMPORTANTNOTE:Ifyoutryandcutandpastetheexamplesinthisdocument,youwillprobably needtomanuallyreplacethespecialcharacterssincethewordprocessormodifiesthemfor presentation.Onescopiedfromthecommandlinewillbeokay,butonestypeddirectlyintothis documentwillneedtobecorrected.Theseinclude,butarenotlimitedto'`/\| Command:grep Description:matchesastringfrominput Examples: 1) findallfilesthatendin.tar ls|grep".tar$" 2) findalllinesinafilethatdonotcontainthestringerror,regardlessofcase grepiverrormessages.log 3) matchoneormorestrings(thiscanbeegreporgrepEalsoseefgreporgrepF) egrep123|abc|wxysomefile.txt Command:cat Description:displayorjointestfiles Examples: 1) printafiletostandardoutput(thescreen) cat/etc/hosts 2) joinfile1andfiles2savingthemasfile3

1of3

OverviewofaFewCommonCommands
PeteNesbitt May2006

LinuxShellCommands

catfile1file2>file3 Command:sed Description:replacestring1withstring2 Examples: 1) replaceallinstancesofNewwiththeOldfromfile1andsaveasfile2 seds/New/Old/gfile1>file2 2) removethefirstinstanceofthestring123fromastringofnumbersandjustprinttoscreen echo123456123|seds/123// (outputs456123) Command:tr Description:usedtotranslate,deleteormanipulatetextstrings Examples: 1) changeastringfromlowertouppercase echoabcdef|tr[:lower:][:upper:] (outputsABCBEF) 2) removeanycharacters(b,corg)anywhereinastring echoabcdefg|trdbcg (outputsadef) Command:cut Description:separateastringintopieces,outputcertainones Examples: 1) extractthe2ndsetofcolumnseparatedvalues echo123:456:789|cutd:f2 (outputs456) 2) extractthe1stand3rdsetofspaceseparatedvalues echo123456789|cutd''f1,3 (outputs123789) Command:awk Description:manipulatesfieldsfromastring.Unlikecut,theFieldSeparatorcanbemultiple characters. Examples: 1) extractthe2ndsetofvalues echo"abc123def123ghi"|awkF123'{print$2}' (outputsdef)
2of3

OverviewofaFewCommonCommands
PeteNesbitt May2006

LinuxShellCommands

2) extractandreordersomepartofastring echo"abcdefghi"|awk'{print$2,"\t",$1}'

(outputsdefabc)

Command:sort Description:sortsdata. Examples: 1) reversethenaturalnumberorderofaseriesofdigits.Withoutthen,valuessuchas161and 18872wouldbeplacedtogetherinthelistbelow.(lsisusedjusttogetusaquicklistof numbers) lsl|awk'{print$5}'|sortnr outputsaverticallist: 51200 19349 18903 18872 8993 6607 5810 ... 1368 1345 274 222 195 161 141

Therearemanymorewaystousethecommandsshownhereandmanymorecommandsavailable. ThisissimpleaprimertohelpyoustarttoutilizesomeofthepowerofbothscriptingandtheLinux commandlineenvironment. EOF


3of3

You might also like