Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

On This Page
Learn how to use different commands in Linux to clear history, enhance privacy, and manage Bash command line records effectively for security reasons.

Tahneet Kanwal
December 24, 2025
Command history in Linux is a feature that keeps a record of the commands you’ve executed in the terminal or shell, making it easier to recall and reuse them. This enhances efficiency, especially when working with complex or repetitive tasks.
However, there may be times when clearing this history is necessary for privacy or security reasons. Learning how to use different commands in Linux to clear history allows you to better manage and protect your command records.
Typically, the history is stored in a file, such as .bash_history for the Bash shell, in the user’s home directory. You can navigate through your command history using the up and down arrow keys or search through it with specific commands.
Before clearing your history, you can check the commands that have been recorded by using the history command:
$ history
This will display a list of recent commands executed in the terminal, each with a line number.
To view the .bash_history file directly, you can use the cat command:
$ cat ~/.bash_history
There are several ways to clear Bash command history. You can clear specific commands, clear all history for the current session, or completely delete the history file.
Below are the methods:
If you want to clear a specific history, you can use the history -d command. This command is one of the useful commands in Linux to clear history, as it allows you to delete a particular entry from the history list without affecting the rest.
history
history -d 15
history -w
This will overwrite the .bash_history file with the current history in memory, making sure the changes are saved.
If you want to clear all the commands from the current session without deleting the .bash_history file, you can use the history -c command. This is one of the useful commands in Linux to clear history, as it clears the current session’s history, but it does not affect the history saved in the .bash_history file.
history -c
history -w
If you want to permanently clear all the history (including the .bash_history file), follow these steps:
history -c
history -w
rm ~/.bash_history
If you want to prevent Bash from saving commands to the history file temporarily, you can unset the HISTFILE variable:
unset HISTFILE
export HISTSIZE=0
unset HISTFILE
export HISTSIZE=0
source ~/.bashrc
To clear the history automatically when logging out, follow these steps:
nano ~/.bash_logout
history -c
history -w
This will ensure that the history is cleared every time you log out. The history -c command clears the in-memory history, and the history -w command writes the cleared history to the .bash_history file.
In this blog, we have explored different commands in Linux to clear history. Clearing your Bash command line history is an important security measure, particularly when handling sensitive information like passwords or personal data. By using the history command or manually deleting the .bash_history file, you can prevent your commands from being stored and potentially exposed to unauthorized users.
By following the steps outlined above, you can clear specific commands, clear all commands for the current session, or delete the entire history file. Additionally, you can prevent Bash from saving history or set it to automatically clear upon logout for enhanced privacy and security.
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance