Enhancing efficiency with history

Command Line – Bash History

© Photo by Federico Di Dio photography on Unsplash

© Photo by Federico Di Dio photography on Unsplash

Article from Issue 263/2022

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

If you work in a terminal, you've likely used Bash's history command to save yourself the trouble of retyping a command [1] (Figure 1). However, if you're like most people, your use of history may have been confined to scrolling through the list of previously used commands. If all you are interested in are the most recently used commands, the arrow keys may be all that you need. However, the history command is capable of doing much more and in an economical way – especially if you have a good memory. You can start by adjusting history's environmental variables and then learn how to modify history entries for easier searching and for repurposing them using three types of editing options: event designators, word designators, and modifiers. The flexibility of all these options can be combined so that, with a little memorization, you can make the Bash history work for you to save time with minimal effort.

Environmental Variables

The history commmand has several environmental variables. All are added or modified in .profile or .bashrc in your home directory, depending on the distribution. The size of the history file is limited by HISTSIZE, which sets the number of entries in the history, and/or by HISTFILESIZE, the maximum memory to allot for the history. Both have similar structures:



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

  • Back to the Future

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

  • Effectively using Bash history

    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.

  • McFly

    When it comes to working at the command line, using Bash history effectively can save you time. McFly extends the Bash history's features and helps you find past commands more quickly.

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

  • 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

Direct Download

Read full article as PDF:

Price $2.95

Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters