Grepping history

Do you need help remembering that cool command your coworker showed you 10 hours ago? The $ history and $ grep commands are your friend. Here is how you can search your last 500 commands for the word “revert”:

$  history | grep revert

The $ history command in isolation simply returns a list of your 500 latest commands and it is not terribly useful, per se. When the standard output of the history command is piped into grep for parsing, the command becomes invaluable.

If you are just looking for your most recent commands (say your 20 most recent commands) it is best to pipe the standard output from history to the tail command:

$  history | tail -20

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s