[TriLUG] history
Aaron S. Joyner
aaron at joyner.ws
Mon Feb 23 12:51:12 EST 2004
Phillip Rhodes wrote:
> Joseph Tate wrote:
>
>>
>> !100 will execute item 100 in your command history. I generally do a
>> history | grep something, and then !thenumber
>
>
> You can also do !string
> where string is the beginning of a previously
> entered command. This will execute the last command
> starting with that string.
>
> Example:
>
> # ssh someuser at somehost.com
>
> later
>
> # !ssh
>
> will execute the most recent ssh command in history.
>
> TTYL,
>
> Phillip Rhodes
>
Along these same lines, lots of interesting variations are possible in
bash, under "vi" mode. Try: "set -o vi". This allows you to, using the
above ssh example, hit escape (to enter command mode, much like vi),
then enter a regular expression of the form /ssh/ (the trailing slash is
optional). Press Enter and the command will be completed out to the
last command which contained the regular expression specified. For a
more precise match /^ssh would probably be preferred. Generally, if
you're comfortable with vi and it's paradigm of command mode vs insert
mode, this can be a very powerful and functional way to work at the
command line.
Some might ask how this is different from the earlier history | grep
example suggested - the basic answer, it all happens with in the shell
process. No external process overhead is required (so in some
unmeasurable way it might be faster), but more importantly it's a
"gateway" feature. One of those things that once you start using it,
you discover all of the other related things which make life that much
more beautiful. :)
Hope it helps!
Aaron J.
More information about the TriLUG
mailing list