Search command-line history for lines beginning with "git"

134 Views Asked by At

I tried this but it finds nothing:

history | grep "^git"

This finds too many lines:

history | grep "git"
1

There are 1 best solutions below

1
On BEST ANSWER

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