In this tutorial we will see how to use clear command history in Linux terminal to delete command history without trace.
We can clear history in Linux terminal permanently, read more to find out how:
How To Clear Command History In Linux
There are three ways to clear command history in Linux Ubuntu:
- Clear entire command line history using history command
- Clear specific command history using history command
- Clear entire command history automatically at logout
Let us learn about each one of these, one by one:
1. Clear Entire Command Line History Using History Command
To clear the entire command line history in terminal, use the history command:
$ history -c
Or
$ history -cw
The above line of commands will clear the command history or bash history.
2. Clear Specific Command History Using History Command
If you want to delete and clear some particular commands from history list (do not want to clear the entire history), run the following command:
First, run the “$ history” command to get the list of run commands along with their command prefix number.
Note down the command number (number infront of each command from the lsit). Now to clear or delete a particular command from the history, run history command with -d paramaeter and the command prefix number (see below):
$ history -d <number>
Note that the represents the command number of each command to be deleted.
3. Clear Command History Automatically at Logout
If you want to clear bash history automatically at logout you will have to edit ~/.bashrc file. Open and edit the file using the following command:
$ vi ~/.bashrc
Once the file is opne, add the following line:
unset HISTFILE
Now save and close the file.
That’s all now the bash history will be automatically deleted and cleared after you logout from the current session.