history | grep 
history | grep gitthe output would be like that
475  git checkout -f
479  gitx
481  git co sp/sprint1
487  git co master
488  git branch -D sp/sprint1
489  git br
491  git co sp/sprint1
496  git diff | gitx
502  git st
510  history | grep git
the followings will reference to line '502 git st'
> !502
# counting back from the last one
> !-1
# same as !-1
> !!
using the last event starting with 'git'
> !git
Or press Ctrl-R, and as you start typing the search goes back in reverse order to the first command that matches the letters you’ve typed.
Once you’ve found the command you have several options:
- Run it verbatim – just press Enter
- Cycle through other commands that match the letters you’ve typed – press Ctrl-R successively
- Quit the search and back to the command line empty-handed – press Ctrl-G
if you're using the history a lot you may want to add these line to your bash init file (~/.bash_profile)
# remove duplicates from the history
export HISTCONTROL=erasedups
# increases the history size
export HISTSIZE=10000
# ensures that when you exit a shell, the history from the session is appended to bash_history
shopt -s histappend
I copy and pasted from the following articles
working-with-history-in-bash, bash-history-reverse-intelligent-search, man history
i like Bash a lot.
No comments:
Post a Comment