Random Access Command Line History

This afternoon I found out that I knew something I didn’t know I knew (say what?).

I was spending a lot of time opening and closing SSH sessions and some of those were connecting to an IP address that I couldn’t remember. To assist my memory, I was grep’ing my history and then copying and pasting what I needed. At some point in the course of doing that, I had this memory of a way to re-issue a particular command from the history:

me@mine [~] $ history | grep ssh
   13  ssh rob@rob
  297  ssh rob@rwilkerson
  298  ssh rob@rwilkerson1
  299  ssh rob@rwilkerson
  301  ssh rob@rwilkerson-old
  303  ssh rob@10.168.159.174
  432  ssh rob@10.168.159.184
  434  ssh rob@10.168.159.184
  465  history | grep ssh
  466  ssh rob@10.168.159.174
  467  history | grep ssh
  468  ssh rob@10.168.159.174
  501  history | grep ssh
me@mine [~] $ !468
ssh rob@10.168.159.174
rob@10.168.159.174's password:

The first command displays the entire history buffer and pipes it through a grep for the ssh command. The second executes the 468th command in the history buffer, in this case ssh rob@10.168.159.174, without having to retype it or even paste it. Now that I remember that I know how to do this, I suspect it’ll play a larger role in my terminal operations.

Subscribe0 Comments on Random Access Command Line History

Leave your own comment or...subscribe to those of others

Formatting may be applied to comments using Textile markup.