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?
~/.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
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
What to do:
In every open bash shell (you may have multiple terminals open):
history -c history -w
As noted above,
history -c empties the file
~/.bash_history. It is important to note that bash shell does not immediately flush history to the bash_history file. So, it is important to (1) flush the history to the file, and (2) clear the history, in all terminals. That's what the commands above do.
Clear the current shell's history:
When you log out, your current shell's history is appended to ~/.bash_history, which is a cache of previous shells' histories, to a maximum number (see HISTFILESIZE in "man bash").
If you want to remove the history altogether, then you essentially have to empty out ~/.bash_history which many of the above entries have suggested. Such as:
history -c && history -w
This clears the current shell's history and then forces the current shell's history (empty) to overwrite ~/.bash_history....or to be more accurate, it forces it to overwrite HISTFILE (which defaults to ~/.bash_history).
Hope this helps.
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?