Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Exercises:UsingCommands

1. Loginasthesysadminuser: Atthegraphicalloginwindowloginusing username:sysadmin password:<giveninclass> 2. Openaterminalwindow UnderApplicationsmenuopentheAccessoriessubmenuandthenchooseTerminal. Onceyouhaveaterminalwindowopenyoucanproceedwiththeexercises. 3. Viewfiles: Uselstolistfiles: $cd $ls Doyouseeanything?Trythisinstead: $lslah What'sinsideoneofthesefiles? $cat.bashrc [gotoyourhomedirectory]

Try: $less.bashrc Pressqtogetoutofthelessdisplay. Nowtry: $clear $cat.bashrc


AdoptedfromNSRCwithpermission.

Ifyoudon'tunderstandwhatcat,clearorlessdo,thentype: $mancat $manclear $manless And,nowtry: $more.bashrc

4. Workingwiththecommandprompt: Youcanrecoverpreviouscommandsbyusingtheuparrowanddownarrowkeys.Givethis atrynow. Alternately,trytypingthiscommand: $history Ifyouwishtoexecuteoneofthecommandsinthelistyousawtype: $!nn Wherennisthenumberofthecommandinthehistorylist.Thisisusefulifyouwantto runapastcommandthatwaslongand/orcomplicated. Commandcompletion: Withthebashshellyoucanautocompletecommandsusingthetabkey.Thismeans,ifyou typepartofacommand,onceyouhaveauniquestringifyoupresstheTABkeythe commandwillcomplete.IfyoupresstheTABkeytwiceyou'llseeallyouravailableoptions. Yourinstructorwilldemonstratethis,butgiveitatrybydoing: $hist<TAB> $del<TAB><TAB> $rm<TAB><TAB> 5. Workingwithpipes: Wesawanexampleofusingpipeswhenwesortedthecontentsofour/sbindirectoryduring thepresentation.Whatifyouwantedtohavethisinformationavailableinafileandsorted?
AdoptedfromNSRCwithpermission.

[Includethespaceaftertherm]

$cd $ls/sbin|sort>sbin.txt Nowviewthecontentsofwhatisinsbin.txttoverifythatthisworked.Doyouremember howtodothis?Ifnot,gobacktoexercise2. 6. Findingtextstrings: Usethecommandgreptoprintlinesmatchingapatterninadatastream(suchasafile). Forexample,viewtheentryforthesysadminaccountinthesystempasswdfile: $grepsysadmin/etc/passwd

Youshouldseesomethinglike inst:*:1001:1001::/home/sysadmin:/bin/bash Thepreviousitemsaboveare: userid:passwd:uid:gid:Name:HomeDir:LoginShell grepisoftenusedwithapipetoreducethenumberofresults.Forinstance: $history|grepls Willdisplayyourprevioususeofthelscommandfromexercise2. 7. Editingthecommandlinerevisited: Itisparticularlyusefultorealizethatyoucaneditacommandjustasyouwouldalineof textinafile.Forinstance,youcan: Useyourbackarrowandforwardarrowkeystochangetextinacommand. UsetheHomeandEndkeystogotothestartandtheendofacommand. Note:youdonotneedtogototheendofacommandbeforepressing<ENTER>toexecute thecommand. Youcanusethehistorycommandwithgreptofindapreviouscommand.Youcan copyandpastethiscommand,theneditittomakeadjustments.Forlongcommandsthiscan saveconsiderabletime. Alternativelyyoucanusethereversesearchfeatureofbash: 1.)Pressctrlr. 2.)typethetermyouaresearchingfor.
AdoptedfromNSRCwithpermission.

3.)Pressctrlrtocyclethroughalloccurrencesoftheterminyourhistory. 4.)Presstherightorleftarrow,HOMEorENDkeytostarteditingthecommand. Let'sgivesomeoftheseeditingrulesatry: $lslah/usr/share|grepperl*

Then,let'slookforperlin/usr/share/perl5.Trythis: ctrlr,typeperl,thenpressleftarrow.Editthepreviouscommand(whichyoushouldnow have)andadd/perl5pastshare.Usetheleftarrowkeytomove.Youshouldnowhave: $lslah/usr/share/perl5|grepperl* Withyourcursorjustpastthe5inperl5.Press<ENTER>toexecutethecommand. (bytheway,youwon'tfindanything.) 8. Copyandpastingcommands: AnicefeatureinUnixisthebuiltinautomaticcopybuffer(thinkautomaticclipboard). Assoonasyouhighlighttextitisavailableinyourcopybuffer.Youdonotneedneedtouse thectrlc,ctrlvkeyboardcombinationtocopyandpastetext. Afteryouhavehighlightedtext,thenyoucanplaceyourcursorwhereyouwanttopastethe highlightedtextandpressthemiddlemousebuttontodothetextpaste. Givethisatry: $history|grepperl Locatethepreviouscommandfromexercise5andhighlightjustthatcommand.Highlight thecommandtext(notthenumbernexttoit). Nowpressthemiddlemousekey.Thecommandshouldbepastedtoyourprompt. Didthiswork?Nowyoucouldeditthecommandorjustpressentertoexecuteit. Thisisveryusefulifyouhavetwoterminalsopenandwanttousetextfromoneterminalin adifferentterminal.Or,ifyouwishtocopyresultingtextfromacommandinoneterminal intoafilethat'sopeninanotherterminaletc. 9. SoftwareInstallation

AdoptedfromNSRCwithpermission.

Ifyouareloggedinastherootuserpleasedothefollowing: #exit Tobecomeanormaluser,likesysadmin.Yourpromptshould changetoincludea$sign. $ Let'sfigureoutwhatpackageinstallsthelynxtextbasedwebbrowser $aptcachesearchlynx Nosurprisewhatitis...Now,let'sinstallthis: $sudoaptgetinstalllynx Nowlet'suseit... $lynxnsrc.org Press q to exit lynx.

Q.)Whatdoyouthinkishappening? A.)YouareviewingthehomepagefortheNetworkStartupResourceCenter(NSRC) atextbasedwebbrowsercalledlynx.

AdoptedfromNSRCwithpermission.

You might also like