History Lesson

Other Ways to Search

The history file can also be used in other ways. For example, you can pipe history through the grep command, searching for a string with history | grep SEARCH (Figure 4). Another use of the history file is sometimes called a reverse -i search. To use this function, press Ctrl+R and begin entering letters. As in tab completion, each letter entered narrows down the match. When you find the command you want, press Enter to activate it (Figure 5).

Figure 4: Sometimes, an ordinary grep on the history file can be useful.
Figure 5: A reverse search is a type of autocomplete.

As this overview shows, the history command has a greater ability to search than many users realize. It will take practice to find what features fit into your work habits, but learning the ones that work best for you will add just enough sophistication to make working at the command line easier – especially when you have the environmental variables set up to your satisfaction.

Infos

  1. Bash history man page: https://ss64.com/bash/history.html

The Author

Bruce Byfield is a computer journalist and a freelance writer and editor specializing in free and open source software. In addition to his writing projects, he also teaches live and e-learning courses. In his spare time, Bruce writes about Northwest Coast art. You can read more of his work at http://brucebyfield.wordpress.com

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Don't Know Much About History

    The versatile Bash history command can save you time and effort at the command line.

  • Making History

    In the history log, the Bash shell records all commands typed by the user. Mike Schilli extracts this data with Go for a statistical analysis of his typing behavior.

  • Back to the Future

    McFly improves on the venerable history command with a customizable interface and contextualized results.

  • Command Line: Customizing Bash

    Ease into your comfort zone with these tips for customizing Bash.

  • History Lesson

    For admins like Charly, who try to avoid typing at all costs, the shell offers an excellent opportunity to avoid wear on your fingertips in the form of built-in history.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.


News