Learn how to clear Terminal history in Ubuntu. You can clear bash shell history, which means you can clear previous command history from Ubuntu Terminal.
Clear Bash Shell Terminal History Command
To clear the history, type the following command:
history -c && history -w
OR
rm ~/.bash_history
Clear Bash Shell Terminal History on Logout
You can modify the above command to clear the history when you logout:
echo 'history -c' >> ~/.bash_logout
Never Save Bash History File
You can prevent a bash history file from ever being saved. To do so, add the following commands to ~/.bashrc file:
echo 'unset HISTFILE' >> ~/.bashrc
echo 'export LESSHISTFILE="-"' >> ~/.bashrc
Where is Terminal History stored in Ubuntu ?
The Terminal history is stored in a file called “.bash_history” located in the home directory. The file can be edited manually or removed completely by typing the following command in the terminal.
rm ~/.bash_history