<story><title>Advancing in the Bash Shell</title><url>http://samrowe.com/wordpress/advancing-in-the-bash-shell/</url></story><parent_chain><item><author>pmoriarty</author><text>I virtually never use !! any more.  Instead I just type control-r followed by a portion of the command in my history that I&amp;#x27;m interested in.&lt;p&gt;That&amp;#x27;s a much more interactive way of getting to the command I want, and if the first match isn&amp;#x27;t what I want I can either keep typing more of the command or type control-r for the next match.  I can also type control-s to go to the previous match.  For that last trick to work, you need to do something like this first:  stty stop &amp;quot;&amp;quot;&lt;p&gt;Granted, I use zsh, but I think it works pretty much the same in bash.&lt;p&gt;Another trick I really like, which I&amp;#x27;ve only used in zsh, but which might exist in bash too (since bash and zsh have so much feature parity these days) is to bind a keystroke to &amp;quot;insert-last-word&amp;quot;.  When this keystroke is hit, it appends the last argument of the previous command to the end of the current line, further typing of this same keystroke will remove the appended argument and instead append the last argument of the previous command, and so on.  I use this &lt;i&gt;all the time&lt;/i&gt; and therefore never have to type !$&lt;p&gt;And my favorite shell trick of all time:   set -o vi</text></item></parent_chain><comment><author>Myrmornis</author><text>Agreed, but even nicer than control-r are the readline functions `history-search-backward` and `history-search-forward`.&lt;p&gt;Personally I bind them to up&amp;#x2F;down which on OS X at least involves:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  # Put this in some file like ~&amp;#x2F;.readline-bindings
  &amp;quot;\e[A&amp;quot;: history-search-backward
  &amp;quot;\e[B&amp;quot;: history-search-forward

  # And this in your ~&amp;#x2F;.bashrc or ~&amp;#x2F;.zshrc
  bind -f ~&amp;#x2F;.readline-bindings
&lt;/code&gt;&lt;/pre&gt;
That way if you haven&amp;#x27;t typed any input it behaves like normal up (previous command), but if you&amp;#x27;ve typed some characters it only retrieves matching commands.&lt;p&gt;&lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;codeinthehole.com&amp;#x2F;writing&amp;#x2F;the-most-important-command-line-tip-incremental-history-searching-with-inputrc&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;codeinthehole.com&amp;#x2F;writing&amp;#x2F;the-most-important-command-...&lt;/a&gt;</text></comment>
<story><title>Advancing in the Bash Shell</title><url>http://samrowe.com/wordpress/advancing-in-the-bash-shell/</url></story><parent_chain><item><author>pmoriarty</author><text>I virtually never use !! any more.  Instead I just type control-r followed by a portion of the command in my history that I&amp;#x27;m interested in.&lt;p&gt;That&amp;#x27;s a much more interactive way of getting to the command I want, and if the first match isn&amp;#x27;t what I want I can either keep typing more of the command or type control-r for the next match.  I can also type control-s to go to the previous match.  For that last trick to work, you need to do something like this first:  stty stop &amp;quot;&amp;quot;&lt;p&gt;Granted, I use zsh, but I think it works pretty much the same in bash.&lt;p&gt;Another trick I really like, which I&amp;#x27;ve only used in zsh, but which might exist in bash too (since bash and zsh have so much feature parity these days) is to bind a keystroke to &amp;quot;insert-last-word&amp;quot;.  When this keystroke is hit, it appends the last argument of the previous command to the end of the current line, further typing of this same keystroke will remove the appended argument and instead append the last argument of the previous command, and so on.  I use this &lt;i&gt;all the time&lt;/i&gt; and therefore never have to type !$&lt;p&gt;And my favorite shell trick of all time:   set -o vi</text></item></parent_chain><comment><author>Jerry2</author><text>&amp;gt;Granted, I use zsh, but I think it works pretty much the same in bash.&lt;p&gt;I also use zsh and I don&amp;#x27;t even use ctrl+r anymore. I just type a portion of the command I remember and hit the up arrow key. Almost always the command I want is only one to three arrow keys away. zsh matches partial commands really well.</text></comment>