1

I tried this but it finds nothing:

history | grep "^git"

This finds too many lines:

history | grep "git"
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
SL5net
  • 2,282
  • 4
  • 28
  • 44
  • See https://stackoverflow.com/questions/1030182/how-do-i-change-bash-history-completion-to-complete-whats-already-on-the-line – giskard Dec 11 '22 at 14:35

1 Answers1

4

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
konsolebox
  • 72,135
  • 12
  • 99
  • 105
  • 1
    `history | grep "^\d+ git"` is also not working here. `history | grep "\d+ git"` is good but does not guarantee that it is looking for from the beginning. i prefer using `grep '^git' ~/.bash_history` next time. – SL5net Jan 05 '22 at 07:45