How to Manage Command History on Linux
On Linux, every command you type gets saved in the history file. The history command lets you view and reuse those commands without having to retype them. You can navigate through the history list using theUpandDownkeys. However, there may be times you want to delete some commands from the history or permanently disable the history saving feature.
Fortunately, Linux lets you control command logging features, such as disabling it temporarily or permanently, deleting the entire history, or preventing certain commands from being saved in the history list. Let’s see how.
Delete Entire Command History on Linux
To delete the entirecommand history on Linuxfrom the beginning, use the history command with the-coption:
This will erase the entire history of the commands you’ve previously run.

Delete Specific Commands From the History
Sometimes instead of deleting the entire history, you may want to remove specific commands. In this case, you need to determine the number associated with that particular command in the history list. You can do this by simply typing:
Or you can also pipe the history output to grep to find the desired information easier:

Once you have found the command number, you can delete it using the history command with the-doption followed by the command number:
Execute a Command Without Including It in the History
To execute a command without it being recorded in the history, simply add aSpacebefore the command. However, for this feature to work, you will need to set theHISTCONTROLenvironment variable toignorespaceusing the following command:
This change does not persist after a reboot. To make it permanent, add it to your.bashrcfile using the following command:

By enabling this feature, Bash will not record commands beginning with a space character in the history file.
For instance, the following command won’t be recorded by the shell:

If you run the same command without space, Bash will record it in the history:
Similarly, you can also let Bash remove consecutive duplicate commands from history with:
This feature will store the consecutive duplicates only once in the history list.
How to Enable/Disable Command History on Linux
While the previous method can prevent the shell from logging commands in the history, it may not be practical when dealing with a large number of commands.
Inserting a space before each command can become monotonous and burdensome. In such a scenario, you can temporarily disable shell history by executing the following command:
To turn it back on, use the following command:
To permanently disable Linux command history, use:
Ignore Certain Commands From Being Recorded in the History
There may be certain commands you wish to exclude as they may clutter the history list and make it difficult to navigate. Some of the common examples are pwd, ls, man, cat, andthe cd commandas it can be repetitive and superfluous.
Using theHISTIGNOREenvironment variable, you can control which commands shouldn’t be added to the history list. For instance, to exclude certain commands such as history, pwd, and cat from saving in the history list, separate them using a colon and enclose them within double quotes as follows:
To make the change permanent, add the command to the.bashrcfile using:
Control Your Bash Command History on Linux
Linux offers extensive control over managing command-line history, allowing users to specify which commands to save in the history, delete specific commands from the history, enable or disable history temporarily or even delete the entire history.
This not only helps to protect the user’s privacy but also prevents irrelevant or repetitive commands from cluttering the Bash history.
An even better way to access command-line history is using McFly, a neural-network-powered replacement to the default reverse-i-search on Linux.
McFly is a neural network-powered replacement to the default reverse-i-search feature to access command history on Linux.
Flagship price, mid-range phone.
Every squeak is your PC’s way of crying for help.
Your iPhone forgets what you copy, but this shortcut makes it remember everything.
Unlock a world of entertainment possibilities with this clever TV hack.
You can’t call this offline, Notion.