Ubuntu – How to clear bash history completely

bashhistory

I want to clear all previous commands from the history of my server. I used history -c and it seems all things are cleared but when I ssh to the server, all the commands are still there.

How can I clear them permanently?

Best Answer

  • The file ~/.bash_history holds the history.

    To clear the bash history completely on the server, open terminal and type

    cat /dev/null > ~/.bash_history
    

    Other alternate way is to link ~/.bash_history to /dev/null

    However,

    One annoying side-effect is that the history entries has a copy in the memory and it will flush back to the file when you log out.

    To workaround this, use the following command (worked for me):

    cat /dev/null > ~/.bash_history && history -c && exit