Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash history re-runs: possible command to avoid using !bang!?

Scenario:

You are doing your daily Bash shell stuff. You want to run a previous command so you type:

history | grep foocommand

Then you get a list of all the foocommand stuff you did for however long your history has kept track, in a list like so:

  585 foocommand --baz --bleet
  750 foocommand | grep quux
  987 history grep | foocommand

You decide you want to run command 585, so you type

  !585

Question: Just for curiosity, is there a way to take that final step out of the equation and still get the expected outcome? It would be nice if there were a way to say:

 "grep through history and automatically run the first item on the list"

or

"grep through history and let me choose which item to run using the arrow keys"
like image 948
dreftymac Avatar asked Dec 13 '22 05:12

dreftymac


1 Answers

Press ^r (that's CTLR-r), type foocommand press Enter ;) That will search history and show the latest matching entry

like image 173
Tomasz Tybulewicz Avatar answered Jan 20 '23 12:01

Tomasz Tybulewicz