Reverse search

As far as keyboard shortcuts go, we believe we have saved the best for last. Out of all the time-savers we have so far introduced, this is by far the coolest as far as we're concerned: reverse searching.

A reverse search allows you to go back through your history, and search for a string within your executed commands. You can think of this as similar to history | grep cat, but much more interactive and much faster. To enter the reverse search prompt, the keys CTRL+r are used:

reader@ubuntu:~$ # CTRL+r(reverse-i-search)'': # Start typing now.(reverse-i-search)'cat': cat /var/log/dpkg.log # Press CTRL+r again for next match.(reverse-i-search)'cat': sudo cat /etc/shadow # When match is found, press ENTER to execute.reader@ubuntu:~$ ...

Get Learn Linux Shell Scripting - Fundamentals of Bash 4.4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.