Background
Yup you read it correctly. How would you clear terminal history in Linux? Before we see how that is done lets address even better question why would be clean our command line history? I am not going to answer this question for you :). It is same as asking why would you clear your browser history or launch incognito mode ? Sometime we have too - that's all I have.
For Linux users who have not heard about this command just type history in your console and you can see your previously typed commands there.
I personally use it a lot. Specially to SSH to various linux servers (who would remember IP address of each). I simply do
- history | grep ssh
- (Ctrl + R) Start typing your command.
Clear terminal history in Linux
To clear the entire history you will have to execute command
- history -c OR
- history -cw
Note : This may just clear history for current terminal and may not be reflected to in other terminals. This did not work for me on my Ubuntu 14.04 machine.
Deleting the source
Let's go a step ahead. All the bash history is stored in file
- ~/.bash_history
Note : ~ notation is shortcut for current user. History is stored in a file called bash_history which is in root folder of the user.
To clear this file simply use following command
- >~/.bash_history
More details on your history File
Now you know where your history file is. Root folder of your user with file name - bash_history. But this is stored in your environment variable $HISTFILE
- echo $HISTFILE
aniket@aniket-Compaq-610:~$ echo $HISTFILE
/home/aniket/.bash_history
So to disable logging history what you can do is use following commands -
- unset HISTFILE OR
- Turn Off : set +o history
- Turn On : set -o history