History Lesson

Command Line – Bash History

© Lead Image © Scott Rothstein, 123RF.com

© Lead Image © Scott Rothstein, 123RF.com

Article from Issue 214/2018

You can do more with the Bash history command than just using the arrow keys. We show you how to use this command-line tool more efficiently.

If you use the command line regularly, you probably use the Bash history file. Usually located in ~/.bash_history, the history file stores hundreds of previous shell commands, enabling you to reuse them without typing them. If you are like most users, your use of Bash history is largely confined to using the arrow keys to scroll back one or two commands. Yet the history command itself offers dozens of ways to search and reuse the history more efficiently: the regular command options, history expansions, environment variables, and a couple of alternative search commands as well.

The limited use of Bash history may now be common partly because many users today have little command-line experience. Even more importantly, the information available in the history command's man and info pages is verbose and only partial [1]. At best, users pick up isolated tips from how-to articles, which give them little sense of the command as a whole.

Still another reason for not making full use of the history command is the uncertainty about all it can do. For one thing, the command is controlled by several automatically installed environmental variables that users may never see unless they open ~/.bashrc. For another thing, by default, the file collects every entry at the command line, whether the entry is properly formed or not. Additionally, entries from every terminal opened after the first terminal are not collected, but not written, which means the history of all except the original terminal are lost when the window is closed. Such quirks are logical, but arcane enough that it quickly makes the history command a mystery to the average user. What follows is an attempt to systematically explain the different ways you can use history more exactly.


Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

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

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Command Line: Customizing Bash

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

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

  • Bash History on Steroids

    You can always browse the Bash history using your arrow keys, but Bash's search capabilities are very limited. Enter the clever Bash History Suggest Box.

  • Command Line: Fish

    The fish shell provides many features that rival the well-known Bash. We examine some highlights.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95