Instantly Search Your Terminal History With a Keyboard Shortcut

Everyone who regularly uses the command line has at least one long string they type regularly. Instead of entering all that again and again, quickly search your history to find the complete command.

Even if you know use your Bash history in the Linux or macOS Terminal, you might not know about the built-in search functionality, which lets you quickly find the latest command you typed using any series of characters. And it’s easy to use: just open your Terminal on macOS or Linux.

Now press Ctrl+R; you’ll see (reverse-i-search).

Just start typing: the most recent command to include the characters you’ve typed will show up.

Include as much detail as necessary until the precise thing you’re looking for shows up. When it does, press Enter and the command will run instantly.

Yeah, I could have found a more useful example, but you get the idea: press Ctrl+R, type until you see a match, then press Enter.

Screenshots don’t get across how quickly this all works, so here’s a GIF of me pulling up a common command in just a few keystrokes:

Keep this keyboard shortcut handy if there are a few long-ish commands you type on a regular basis, because it’s a huge time saver.

Oh, and if you’re worried about someone else stumbling upon any embarrassing commands, you could clear your Terminal history. I won’t tell anyone.

Justin Pot is a staff writer for How-To Geek, and a technology enthusiast who lives in Hillsboro, Oregon. Follow him on Twitter and Facebook, if you want. You don't have to.