Skip to content

Click on each book below to review & buy on Amazon.

As an Amazon Associate, I earn from qualifying purchases.

LPI Linux Essentials Exam 010-160 - Topic 2.1 - Command History

Command history in Linux is a valuable feature offered by the Bash shell, enabling users to track, recall, and reuse previously executed commands. It's an integral part of the Linux command-line interface, benefiting both novices and experienced users.

The Basics of Command History

At the core of command history is the command history file, typically located at ~/.bash_history for each user. This file serves as a repository, storing a chronological record of all the commands executed by the user. The size of this history file is determined by the HISTSIZE environment variable, which can be configured in the user's shell configuration file, often ~/.bashrc.

Viewing History

The history command is the primary tool to access and manage the command history. By simply typing history in the terminal and hitting Enter, users can view a list of their recently executed commands, with line numbers for reference. This helps users recall what they have done, particularly in complex tasks or when they need to reproduce certain steps.

Exercise: View command history

Use the history command to few commands that have previously been run:


Your output will be different but an example of the first 5 rows could be:

1  ls
2  cd Documents/
3  nano myfile.txt
4  grep "pattern" file.txt
5  ssh user@remotehost

Recalling Commands

One of the most convenient aspects of command history is the ability to recall and execute previous commands. This can be accomplished by using the ! symbol followed by the command number. For instance, !5 will execute the command with the line number 5 in the history (the ssh command in the previous exercises example output), allowing for easy repetition of specific operations.

Searching History

Searching through the command history is also made simple. The Ctrl+R shortcut initiates a reverse search feature, letting users input a portion of a command they want to find. The system will locate the most recent match from the history and display it, offering a quick way to access and re-execute commands with minimal keystrokes.

Using Arrow Keys

Navigating through the command history is made effortless with the use of the up and down arrow keys. This provides a more intuitive and interactive method of accessing previous commands, as the displayed command changes with each keystroke, allowing users to quickly scroll through their history and select the desired command.


In conclusion, the command history feature in Linux plays a vital role in enhancing productivity and efficiency for users. It helps in reducing the effort required for repetitive tasks, learning from past commands, and maintaining a log of all interactions with the command-line interface. Customizing the behavior and size of the history can be done by adjusting environment variables and shell configuration files to suit individual preferences.

Support DTV Linux

Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.

NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.