Quickzi: How To Delete Bash History

If you want to delete your bash history, there are a few options you have.  First you must understand that the history of your bash session is stored into RAM and then written to ~/.bash_history when you log out of the bash session.  So even if you delete the ~/.bash_history file, your current bash session will still be written to history once you log out.

Delete bash history

To delete the bash history for your current session as well as old sessions, you should do two things:

Delete the .bash_history file:

# rm -rf ~/.bash_history

Clear the current history stored in RAM:

# history -c

Stop writing to .bash_history for good

If you don’t want to log any history for good, you can do one of two things; turn it off for all users, or turn off logging history for a single user.

Turn off bash history for all users:

Append “unset HISTFILE” to /etc/profile:

# echo "unset HISTFILE" >> /etc/profile

Turn off bash history for a specific user:

Append “unset HISTFILE” to /home/USER/.bash_profile:

# echo "unset HISTFILE" >> /home/USER/.bash_profile

That’s it! Now you have successfully deleted the bash history and stopped logging to bash history.

6 thoughts on “Quickzi: How To Delete Bash History

  1. The -rf is completely unnecessary, and will only break things if you typo something else in the command.

  2. I created the following alias:

    alias clearhist=’rm ~/.bash_history && history -c && exit’

    This seems to clear everything without leaving any sort of trail…

    (It was created based on this site, I must confess)

  3. Disable the usage of history using HISTSIZE

    1. HISTSIZE=0
    export HISTSIZE

    2. Force history not to remember a particular command

    export HISTCONTROL=ignorespace

    3. Ignore specific commands from the history using HISTIGNORE

    export HISTIGNORE=”vi:ls -alrt:ifconfig” …etc


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>