How to Clear the Ubuntu ‘Bash History’ (Delete Terminal Command Logs)

When you use the Terminal in Ubuntu Linux, the default Bash shell automatically records every single command you type and saves it to a hidden text file in your home directory (.bash_history). This is incredibly useful for recalling a long, complex string you typed yesterday by simply pressing the “Up” arrow key.

However, if you accidentally type a sensitive password in plain text instead of at a secure prompt, or if you are demonstrating something on a shared computer and want to hide the server IP addresses you recently connected to via SSH, you need to scrub this file. Simply closing the Terminal does not erase the history; you must explicitly clear the Bash logs.

How to Clear the Bash History in Ubuntu Linux

You can clear your current session history and permanently delete the saved log file using two quick commands.

  1. Open your Terminal application (Ctrl + Alt + T).
  2. First, you must clear the history of the current terminal session that is held in RAM. Type the following command and press Enter: history -c
  3. Next, you must delete the physical log file stored on your hard drive. This file will simply be recreated empty the next time you open a terminal. Type the following command and press Enter: rm ~/.bash_history
  4. To ensure that your now-empty RAM history doesn’t overwrite the file with old data when you close the window, type this final command to write the empty state to disk: history -w

Your terminal history is now completely erased. If you press the “Up” arrow key, nothing will happen. If you want to view the contents of the history file to verify it is empty, you can type cat ~/.bash_history (it should return absolutely nothing). Keep in mind that this only clears the history for your specific user account; it does not clear the history for the root user.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.