1

I'm using Ubuntu.

there is a way to get a list of all the commands I entered that starts with the word: "git"?

3 Answers 3

4

You could use history and awk together.

history | awk '$2 ~ /^git/ { print }'

Use $2 or $3 depending on the output of your history command. As Andreas pointed out, it depends on the shell that you are using. In bash, it will not include the time stamp. This can be adjusted accordingly.

5
  • 1
    history prints the time stamp at the beginning of the line, so ^ does not match
    – Andreas
    Feb 14, 2013 at 8:31
  • @Andreas We could use awk then. Do you mean time stamp or number?
    – squiguy
    Feb 14, 2013 at 8:33
  • Well, both of them :) history prints something like 111 8:28 git status, means that the line is at least not starting with git
    – Andreas
    Feb 14, 2013 at 8:34
  • @Andreas Updated, now that should work better!
    – squiguy
    Feb 14, 2013 at 8:40
  • +1 Excellent - good catch on using either $2 or $3, you could mention that it primarily depends on the shell
    – Andreas
    Feb 14, 2013 at 8:43
4

You can either do an interactive backwards search with Ctrl+R or search your history with

history| egrep git
1

to know what entered in linux shell

$ history | grep 'git'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .