Searching your shell command history

Recently I was working with a colleague through Zoom and sharing my screen. As he watched me furiously tapping my up arrow key like I was playing a Mario Party mini game to cycle through my history of Unix commands, he gave me a great tip. To search through the history of previous commands you can pipe the history through grep:

history | grep "search term"

Essentially, this command says, “take all my history, send it to grep, and give me results for my search.” The results of the search will then be displayed to your terminal window. I found this tip to be incredibly useful and it has saved some wear and tear on my up arrow.

Leave a comment

Your email address will not be published. Required fields are marked *