How to Delete History in Linux Easily

Last updated: July 13, 2022

The .bash_history file located in the user’s home directory keeps the history of commands you typed on the terminal. This helps users to reuse listed commands without retyping it.

If you don't want others to see your typed commands for any reason, you can easily delete the history. In this guide, we learn how to delete history from Linux.

1. Delete History List Command Line

To see your bash history using history command, type:

$ history 
 1 history 
 2 vim .bash_history 
 3 exit
 4 history

To delete history list from the command line, use the following commands:

$ history -c
$ history -w

2. Delete specific command from history

From the history list if you want to delete specific command, use the following syntax:

$ history -d <line-number>

For example to delete the sixth entry history list, type:

$ history -d 5
$ history -w

3. Delete history without a trace

To clear the bash history completely without a trace on the server, one solution is to link ~/.bash_history to /dev/null.

$ cat /dev/null > ~/.bash_history

Alternatively, you can use the wipe tool to securely delete .bash_history file:

$ wipe ~/.bash_history

4. Turn off bash history

The $HISTFILE variable store the bash history file location.

You can stop history logging into the history file by adding unset HISTFILE to user profiles.

$ echo "unset HISTFILE" >> /etc/profile
$ echo "unset HISTFILE" >> /home/tom/.bash_profile

Alternatively, you can set zero values to HISTSIZE and HISTFILESIZE in the .bashrc file.

5. Delete History Range

If you want to delete N lines from the bash history, you may use the following one-liner.

for i in {1..N}; do history -d START_POSITION; done


START_POSITION is the line number in the history list from where you need to start deleting.

N is no of the entries you want to delete.

For example to delete 13 entries from line 986, type:

for i in {1..13}; do history -d 986; done


In this guide, we learned how to clear history in Linux. Thanks for reading, please share your feedback and suggestions in the comment section.

About The Author

Bobbin Zachariah

Bobbin Zachariah

Bobbin started his career in IT in the year 2000 as a computer science instructor and worked as a Linux system engineer and senior analyst roles. Currently working in DevOps environments to increase efficiency and improve delivery time in AWS Cloud infrastructure. He is certified in RHEL, CCNA, and MCP and holds a Masters's in computer science. When in his free time love playing cricket, blogging, and listening to music.



Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment