The Bash shell, which powers the default terminal emulator on Ubuntu Linux, maintains a rolling log of every command you type. This log is stored in a hidden file in your home directory (~/.bash_history). When you press the “Up” arrow key on your keyboard, you are actually scrolling through this history file, allowing you to quickly execute complex commands you used yesterday without retyping them.
However, Bash has a strict limitation. By default, it is configured to only remember the last 1,000 commands (or sometimes 2,000 depending on the Ubuntu version). Once you hit that threshold, Bash automatically deletes your oldest commands to make room for new ones. If you rely on your history file as a reference guide for obscure ffmpeg or docker commands you only use once a month, having Ubuntu silently erase them is incredibly frustrating.
You can edit your Bash configuration to completely remove this limit, forcing the terminal to permanently remember every command you ever type.
How to Stop Bash from Deleting Command History
You need to modify the HISTSIZE variables in your personal .bashrc file.
- Open your terminal application (
Ctrl+Alt+T). - Open your bash configuration file in a text editor like Nano:
nano ~/.bashrc
- Use the arrow keys to scroll down until you find the following two lines:
HISTSIZE=1000
HISTFILESIZE=2000
- Change the numeric values to a massive number, or simply remove the limit entirely by setting them to a blank space (or a negative number depending on your Bash version). The safest method to essentially make it infinite is to add several zeros:
HISTSIZE=1000000
HISTFILESIZE=1000000
- Press
Ctrl+O, thenEnterto save the file. - Press
Ctrl+Xto exit the editor. - To apply the changes immediately, reload the configuration file by running:
source ~/.bashrc
Your Ubuntu terminal will now successfully store up to one million commands. You will never again lose a complex, multi-line command to the automated history cleanup cycle.