Command History Searching

Use C

Using this trick you can speed up a lot your work at command line in Linux (and not only). Pressing Ctrl + R allows you to quickly find a previously used command.

How to use it?

  1. In command line terminal press Ctrl + R.
  2. Start typing some part of command, for example `pul`:
    (reverse-i-search)`pul': git pull
    • If you want to find a next match, press Ctrl + R again (repeat until successful).
    • If you want to edit the current match press LEFT or RIGHT and edit the command.
    • If you want to exit without running any command, press Ctrl + G.
  3. If command you need is displayed, press ENTER to run it.

Useful shortcuts

These shortcuts are not related to the bash history tool (Ctrl+R), but may be useful if you edit a found command.
  • Ctrl + LEFT/RIGHT - jump over the words.
  • Ctrl + A - move the cursor to the beginning of the line.
  • Ctrl + E - move the cursor to the end of the line.
  • Ctrl + U - remove the content from the beginning of the line to the cursor.
  • Ctrl + K - remove the content from the cursor to the end of the line.
  • Ctrl + W - remove word on the left.
  • Ctrl + C - cancel the current command line.


To tag a command you can use a normal bash comment. Then using Ctrl + R search the command by assigned tag.

  1. Tag a command:

    $ somecommand #mytag

    Everything after `#` in the line is ignored by bash, but remains in history.

  2. Search by tag:

    (reverse-i-search)`my': somecommand #mytag

What about Windows?

In the standard Command Prompt in Windows the Ctrl + R shortcut as a bash history tool is not available. But you can install an optional shell like Git Bash where the Ctrl + R tool is available.


Popular posts from this blog

Special relativity: Train-platform paradox

Vibrating string equation (without damping)

PyCharm - useful shortcuts