When you use the Terminal in Ubuntu Linux (or any Linux distribution using the Bash shell), the system actively records every single command you type. This allows you to press the “Up” arrow on your keyboard to quickly repeat a command you used ten minutes ago.
However, if you accidentally typed a plain-text password into the terminal, or if you connected to a secret server IP address, that highly sensitive information is now permanently recorded in a hidden text file on your hard drive. If you share the computer, anyone can simply open the terminal and press the Up arrow to see exactly what you did. To protect yourself, you must safely erase this specific command history.
How to Safely Erase Ubuntu Bash Command History
You must wipe the active memory cache and then permanently delete the hidden `.bash_history` log file.
- Open your Terminal application (Ctrl + Alt + T).
- First, you must erase the “live” history that is currently stored in the computer’s RAM. If you don’t do this, Ubuntu will just write the history back to the hard drive when you close the window. Type this command and press Enter:
history -c - Now, you must securely overwrite the hidden physical log file on your hard drive. Type the following command (which forces the system to write nothing into the file) and press Enter:
cat /dev/null > ~/.bash_history - Finally, to ensure these two commands themselves aren’t logged, close the terminal window completely and open a fresh one.
Press the Up arrow key on your keyboard. Nothing will happen. Your entire terminal command history has been completely and safely obliterated. The Bash shell will simply begin recording a brand new, clean history from this moment forward.