How to Stop Ubuntu from Automatically Clearing the Terminal History

The Vanishing Commands

In Ubuntu (and most Linux distributions using the Bash shell), your terminal keeps a running history of the commands you type. This allows you to press the “Up” arrow to easily recall complex scripts or long paths. However, some security-focused setups or specific user configurations employ a script (often .bash_logout) that automatically executes a command like clear_console or explicitly deletes the .bash_history file the moment you close the terminal window or log out of a session. While highly secure for public terminals, this is incredibly frustrating for developers who rely on their command history to remember how they compiled a program three days ago.

Preserving Your Terminal History

To ensure your past commands are saved across sessions and stop Ubuntu from automatically clearing the terminal history upon logout, you must inspect and modify your bash logout script.

You need to check the hidden logout file in your home directory. Open your terminal (Ctrl+Alt+T). Type nano ~/.bash_logout and press Enter. This file contains the commands executed when a login shell exits. Look for any commands that look suspicious, specifically clear, clear_console, or anything referencing rm ~/.bash_history. If you see these commands, you can disable them by typing a hash symbol (#) at the very beginning of the line to comment them out. Press Ctrl+O then Enter to save, and Ctrl+X to exit. Your terminal history will now safely append to the hidden .bash_history file and survive reboots.

Get the best tech tips delivered straight to your inbox.

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