By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

Controlling the Terminal History

How to manage the bash history in unix based systems.

Edited: 2013-06-28 11:26

Sometimes you end up having a bloated history in your terminal, perhaps after entering in hundreds of commands over a period of time – the good news is that it can be easily cleared.

Typically you will be able to jump between items in the history by using the up and down arrow keys. If you prefer not to have terminal remember commands that you type, you can also turn off the bash history entirely for the current session.

Before we get started, we should also mention the CTRL+R shortcut key, pressing them while in a terminal window will bring up a search function, which allows you to search your history.

Note. The following should work in most unix based systems!

Clearing terminal history

The .bash_history file contains a limited number of recent commands that you typed into the terminal. Using the rm (remove) command on the file will delete it, forcing terminal to create a new file next time its saving its history.

rm ~/.bash_history

Stopping terminal from remembering commands

By default the terminal will remember recent commands, and save them into ~/.bash_history when you exit – to stop this from happening, you can clear the history before closing the terminal. I.e.

history -c

If you want to permenantly stop terminal from saving history, write the below settings to your .bashrc or .bash_profile file.


Change how many commands are remembered by terminal

Increasing or decreasing the number of commands that the terminal will remember can be done using the following commands.

export HISTSIZE=0

You can save them in your .bashrc or .bash_profile file to make the changes permenant.