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

  • 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.

  • 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.

  • Bash Tricks

    The Bash shell is powerful and infinitely expressive. In this article we describe some tricky techniques you can use to enhance and customize your Bash environment.

  • Introducing Bash

    Beyond all the splash screens, screen savers, and vivid rock-star wallpaper is the simple yet powerful Bash shell.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News