Thursday 1 August 2019

grep: how to use grep to search history (linux)

I often remember only part of something I did before and want to remember how I’ve done something. To easily search through the history, the glorious grep can be invoked like this:

history | grep phrase_to_search_for

If the phrase to search for involves spaces or special characters, then quotes can be used around the phrase:

history | grep "phrase to search for"

To search for something with quotes, you can surround your phrase-to-search-for with the ‘other’ kind of quote.

For example,

history | grep 'phrase to "search" for'

will match

phrase to "search" for

and

history | grep "phrase to 'search' for"

will match

phrase to 'search' for

0 comments:

Post a Comment