Home » Scripting and Automation » Bash / Shell Scripts » How To Clear Shell History In Ubuntu Linux ?

How To Clear Shell History In Ubuntu Linux ?

When you type something on linux shell, by default Linux save the commands what you type as history to “~/.bash_history” or /home/username/.bash_history file so that you can easily check what you have typed previously using “history” command.

 $ history | tail
 1998  sudo apt-get install mdns
 1999  sudo apt-get install mdns-scan
 2000  sudo mdns-scan

As you can see, we just showed last output of “history” command. You can use only “history” without “tail” to see all the complete history.

Clearing history

The easiest way to clear history is to use “history -c” command for the current terminal. This command only clears history of current terminal and if you close the terminal and start again, you will see the last saved history from “~/.bash_history” file.

$ history -c

If you want to wipe-out all the history so that even after restarting of terminal it shouldn’t show any details, you will need to clear the “~/.bash_history” file contents.

$ echo "" > ~/.bash_history

Now, if you close and open the terminal, you will not see any history.

Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment