Productive— faster every day
For your professionTeachersStudentsManagersMarketingDevelopersFreelancersParents

Tips & tricks · Shortcuts · Everywhere · ~5 min a day · 3 min read

Ctrl+R in the terminal: type a piece of a command, history finds it

Last reviewed:

Ctrl+R

Illustration for: Ctrl+R in the terminal: type a piece of a command, history finds it

The up arrow is the slowest way to get back to a command you typed two days ago — fifty other commands stand between you and it. Ctrl+R launches a reverse search through your history: you start typing any fragment of the command you're looking for (even from the middle), and the shell instantly suggests the most recent command that contains it. It works in bash, zsh, and PowerShell, making it one of the few shortcuts you can rely on on almost any computer.

How to do it

  1. In the terminal, press Ctrl + R — a reverse-search prompt appears on the line (in bash it looks like (reverse-i-search)).
  2. Type any part of the command you're looking for — say just migrate or a filename. It doesn't have to be the start of the command; the search matches anywhere inside it.
  3. The shell immediately shows the most recent matching command from history. If it's not the right one, press Ctrl + R again — you'll move to an older match, and you can repeat this as many times as you like.
  4. Enter runs the found command right away. The right arrow or Esc instead drops it onto the line for editing — handy when you just want to change one parameter.
  5. Cancel the search with Ctrl + G (in PowerShell, Esc) to return to an empty line.

A typical scenario

A developer ran a database export last week with five flags — she obviously doesn't remember the exact combination. Instead of scrolling with the up arrow or hunting through notes, she presses Ctrl+R, types dump, and the whole command appears, down to the last flag. Enter, done, five seconds. The same trick works for “how do I even connect to that test server again” — all she needs is to recall a single word from the command.

Over time it becomes a habit that changes how you work: you stop copying long commands out of documentation, because you know that once you've typed a command, you'll always find it again in a few keystrokes. Your shell history turns from a trash bin into a personal cookbook. And when you find yourself pulling the same command out via Ctrl+R day after day, that's a reliable sign it deserves its own shortcut — which is what the tip on aliases and scripts is about.

What you get out of it

The most common terminal activity — “run again what I've typed before” — shrinks from tens of seconds of scrolling to two or three keystrokes. You stop saving long commands into text files and pasting them with the mouse. And because the shortcut works in bash, zsh, and PowerShell, the habit follows you to every machine you log into. There's just one condition: the shell has to be storing history — if Ctrl+R only finds you the last few commands, increase the history limit in your shell config (the HISTSIZE and HISTFILESIZE variables) so your cookbook reaches months into the past.