Beruflich Dokumente
Kultur Dokumente
com/writing/themostimportantcommandlinetipincrementalhistory
searchingwithinputrc/
Keywords:
LinuxuparrowhistoryrecallcommandcompletionDebianUbuntuCentOS
codeinthehole.com
writing|twitter|github|about
Themostimportantcommandlinetip
incrementalhistorysearchingwith
.inputrc
byDavidWinterbottomonTuesday,3February2009
Note,thisarticlewaspublishedover5yearsagoandhencethecontentmaybestale.
Consumewithapinchofsalt.
Gettingwww.commandlinefu.comoffthegroundhasrenewedmyinterestinBash,UNIX
andallthingscommandline.Powerfulonelinersarethingsofbeautyandareworth
collectinghoweverwhatIconsidertobethemostinfluentialcommandlinetipIknow
coversfour:
"\e[A":historysearchbackward
"\e[B":historysearchforward
"\e[C":forwardchar
"\e[D":backwardchar
Theselinesneedtobeplacedinyour~/.inputrcfile,thestartupscriptfortheReadline
utilityusedbyBash(aswellasseveralotherapplications)andothers).Theimportant
commandsherearethefirsttwo,whichbindyourupanddowncursorkeysto
incrementallysearchyourhistory.(Thesecondtwoensurethatleftandrightcontinueto
workcorrectly).
Thisisincrediblyusefulforretrievingcommandsyou'veusedpreviouslyandmakesa
hugedifferencetoyourproductivity.Forinstance,tofindapreviousSSHcommandfroma
fewdaysago,simplytype"ss"andpressupafewtimes.Thiswillallowyoutobrowse
throughallyourprevioussshcommandsuntilyoufindtherightoneyouneverneedto
usemorethan4or5keystrokestoretrieveanypreviouscommand.Ifyourcyclingthrough
toomanycommandstofindtherightone,typeinafewmorecharacterstorefinethe
search.
Asindicatedabove,thisfunctionalityisavailableinallapplicationsthatuseReadline
includingMySQL,Python,IRB(interactiveRubyshell)andothers.Onceyou'reusedto
thisfeature,it'shardtolivewithoutthefirstthingIdoonceI'vebeensetupasauseron
anewserverisupdatemy.inputrcfiletocontainthesesettings.TheoneplacewhereI
sorelywishthisfunctionalityexistedistheFirebugJavascriptcommandlineinFirefox(a
ticketalreadyexistsrequestingasimilarfeature).
AnotherwayofsearchingyourhistoryistouseCTRL+R,whichessentiallyperformsa
fulltextsearchonyourhistory(keeppressingCTRL+Rtocyclethroughresults).Inthis
case,searchingfor"ssh"willlocateallcommandsthatfeaturethisstringanywhereinthe
command.Althoughthisisactuallyamorepowerfulfeaturethantheincrementalhistory
searchdescribedabove,Idon'toftenuseitas:(a)theincrementalsearchgenerallylets
mejumptothedesiredcommandinfewerkeypressesand(b)Ifind"ssh",CTRL+R,
CTRL+Rslightlyawkwardtotypeandlessintuitivethan"ssh",UP,UP.Horsesforcourses
reallyyoucouldprobablybejustasefficientwitheitherone.
HattiptotheplacewhereIfirstlearntthis:PowerShellUsagebySimonMyers
Oneextrathing:thisfunctionalitycanbeneatlycomplimentedbysomechoicehistory
settingsinyour~/.bashrcfile:
exportHISTSIZE=1000000
exportHISTFILESIZE=1000000000
Thesesimplysetyourhistorytobeverylargesothatyouhaveahugebankofcommands
tosearch.
Comments
Related
Sunday,26October2008
commandlinefu,
mysql
MonitoringMySQL
watchingmysqladminftw
Sunday,23November2008
commandlinefu,
mysql
CheckingallMySQLtables
UsingthecommandlinetobuildastringofCHECKcommands
Thursday,22January2009
commandlinefu
Currentpetproject:CommandLineFu
Creatingasiteforsharingcommands
Sunday,22August2010
commandlinefu,
phing
Phingtrickforavoidingdeployingdebugcode
Usingthefuwithwithphingtopreventfurtherembarassments
Friday,5November2010
commandlinefu,
mysql
mysqldumpwithwildcardtablematching
Usingthefutoenhancemysqldump
Saturday,12March2011
commandlinefu,
presentations
CommandlinefupresentationatConfoo2011
Linktoslidesavailablehere
Allarticles
Popular
Saturday,20October2012
commandlinefu,
git
Effectivepullrequestsandothergoodpracticesforteamsusinggithub
Notesfromaninternalgitworkshop
Thursday,5January2012
mysql,
python,
ubuntu
HowtosetupMySQLforPythononUbuntu
Thisdoesn'tstickinmyhead
Saturday,20August2011
Usingpipandrequirements.txttoinstallfromtheHEADofaGithubbranch
Alwaysgetthelatestversion
Monday,5March2012
Tipsforusingagitprecommithook
Yetanothergittipsarticle
Thursday,10November2005
WritingaThesisinLaTeX
Ashortguidetogettingthingstolooknice
Friday,3September2010
HowtosyncaMySQLtablebetweentworemotedatabases.
Trickierthanyoumightthink
Populararticles
python
git
latex
mysql
Hello
I'mDavidWinterbottom,aminimalisthackerlivinginLondon.
I'maTechnicalDirectorofTangentSnowball,adigitalagency.IprogrammainlyinPython
buthavestronginterestsinalldynamicandfunctionallanguages.
Ispendmostofmyfreetimehacking.Iruncommandlinefu.comandamtheauthorofthe
ecommerceframeworkdjangooscaramongstotherthings.
IusedtobeamathematicianIhaveaPhDinMathematicsfromtheUniversityof
Nottinghamandanassociatedinterestincrypticcrosswords,chessandplayingdevil's
advocate.
Ifyou'vereadthisfar,youshouldprobablyfollowmeonTwitter:
More
DavidWinterbottom