How to clear bash command line history in linux?

Overview

The history command shows the recently-executed commands recorded in a history list.

How to clear bash command line history in linux

history

Sample Output

415 cd /var/www/
416 ls
417 cd Our\ Beginning/
418 ls
419 cd album/
420 ls
421 vi index.html
422 pwd
423 vi index.html
424 cd ..
425 ls
426 cd ..
427 ls
428 pwd
429 ls

To clear the history use the -c flag. You also need to remove the .bash_history file under your home directory.

history -c
rm ~/.bash_history

I normally like to use alias of frequently used commands. You can create an alias to clear history and can run it once you finish.

vi ~/.bashrc
alias clearhist=’rm ~/.bash_history;history -c;exit’

Next time you wish to clear the history and exit out of the session execute

clearhist

Another trick to disable your command history form being recorded is to set HISTFILESIZE variable to zero. Once you ssh to the server execute

export HISTFILESIZE=0

This will set the history file size to zero for this session only. Your command history will not be saved :)