#!/bin/bash
Saturday, April 15, 2006 8:22:42 AM
…cheat-sheet - I keep forgetting one or the other of the useful expansions and substitutions bash has to offer…
<b># expansions</b> !$ # expands to the end of the last command !* # expands to all arguments of last command !! # expands to last command !<i>number</i> # expands to command <i>number</i> in `history` !-<i>number</i> # expands to command <i>number</i> commands ago !<i>abc</i> # expands to the last command starting with <i>abc</i><br /><br /> <b># modifiers</b> :p # only <b>p</b>rints output :h # only <b>h</b>ead, removing trailing component(s) :t # only <b>t</b>ail, removing leading component(s) :r # <b>r</b>emoves trailing suffix of the form <i>.xxx</i> :e # removes all but trailing suffix :<i>number</i> # <i>number</i> of arguments of last command - therefore !:<i>number</i>* # is from <i>number</i> to end of arguments of last command… and !* # is a shortcut for <i>!:1*</i><br /><br /> <b># substitutions</b> :s/<i>wrong</i>/<i>right</i>/ # <b>s</b>ubstitution of <i>wrong</i> with <i>right</i> in the command :g # <b>g</b>lobal (as a modifier to :s) - as in <i>:gs/<i>wrong</i>/<i>right</i>/ & # repeats previous substitution ( :s/one/&.more/ ) ^<i>wrong</i>^<i>right</i> # replaces <i>wrong</i> with <i>right</i> in the previous command, and runs it</pre> <h4 id="note">Additional note</h4> <p><kbd>^R</kbd> incrementally searches your command history backwards - hit it again to get to the next occurrence. I badly miss the ability to search your buffer in xterm - rxvt-unicode offers this neat feature.</p>


towolf # Sunday, June 11, 2006 11:55:37 PM
"\e[5~": history-search-backward
"\e[6~": history-search-forward
Did you know about this one in inputrc? It’s ^R and !abc combined. Neat.