Bash tip: search history

I am lazy. And I am a developer. Some would even say that I am a developer because I am lazy.

Also, my memory is not what it used to be. So, often times, I can not remember the exact syntax of a command I kind of recall typing in the bash shell.

For example, I kind of recall that in order to build and deploy one particular app for QA, I need to run a gradle task with a parameter containing the letters “QA”. But I don’t recall the specific format.

Here comes history to the rescue. A fuzzy search on the history is easy:

$ history|grep QA
  278  ./gradlew internalQA --info
  279  ./gradlew clean internalQA --info
  280  ./gradlew clean internalQA --info
  287  ./gradlew internalQA
  290  ./gradlew clean internalQA

Now, I can execute any of those particular results directly by number, just doing:

$ !279

Leave a Reply

Your email address will not be published. Required fields are marked *