The Bash history command lists your numbered command history
-- all of
it by default. Other than limiting the output to the most recent N
commands, it doesn't give you any real control over the output. As a
consequence I often find myself typing things like
history | grep find
or even (I use find a lot)
history | grep find | grep cpp
I found myself doing this so much that I eventually bit the bullet and
wrote a better history command provides built in grep-like
filtering.
So now I can type things like
hist find
hist find cpp
hist find cpp viewsource The last command corresponds to something like history | grep -i find | grep -i cpp | grep -i viewsource which is a pain to type in full. I've been using hist for a while now, and I've found it very useful, so I thought I'd share it in case there are other Bash users out there who might find it handy. If you want to use it just paste the following into your .bash_profile: # Quick and dirty case-insensitive filtered history command.
# "hist" ==> "history"
# "hist foo" ==> "history | grep -i foo"
# "hist foo bar" ==> "history | grep -i foo | grep -i bar"
# etc.
# Note that quotes are ignored, e.g.
# <<<hist "foo bar">>> is equivalent to <<<hist foo bar>>>
hist()
{
HISTORYCMD="history $@" # "foo bar" ==> "history foo bar"
HISTORYCMD="${HISTORYCMD% }" # "history " ==> "history" (no trailing space)
eval "${HISTORYCMD// / | grep -i }" # "history foo bar" ==>
# "history | grep -i foo | grep -i bar"
}
hist find cpp
hist find cpp viewsource The last command corresponds to something like history | grep -i find | grep -i cpp | grep -i viewsource which is a pain to type in full. I've been using hist for a while now, and I've found it very useful, so I thought I'd share it in case there are other Bash users out there who might find it handy. If you want to use it just paste the following into your .bash_profile: # Quick and dirty case-insensitive filtered history command.
# "hist" ==> "history"
# "hist foo" ==> "history | grep -i foo"
# "hist foo bar" ==> "history | grep -i foo | grep -i bar"
# etc.
# Note that quotes are ignored, e.g.
# <<<hist "foo bar">>> is equivalent to <<<hist foo bar>>>
hist()
{
HISTORYCMD="history $@" # "foo bar" ==> "history foo bar"
HISTORYCMD="${HISTORYCMD% }" # "history " ==> "history" (no trailing space)
eval "${HISTORYCMD// / | grep -i }" # "history foo bar" ==>
# "history | grep -i foo | grep -i bar"
}