Home > database >  Search command-line history for lines beginning with "git"
Search command-line history for lines beginning with "git"

Time:01-05

I tried this but it finds nothing:

history | grep "^git"

This finds too many lines:

history | grep "git"

CodePudding user response:

The history command shows numbers before the actual commands so try using this awk command instead:

history | awk '$2 == "git"'

Or

history | awk '$2 ~ /^git/'

You can also just search ~/.bash_history but the contents of this file may not always reflect the current history:

grep '^git' ~/.bash_history
  •  Tags:  
  • Related