Tuesday, May 7, 2024
 Popular · Latest · Hot · Upcoming
478
rated 0 times [  478] [ 0]  / answers: 1 / hits: 869059  / 2 Years ago, fri, september 9, 2022, 11:20:32

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?


More From » bash

 Answers
4

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

[#35375] Saturday, September 10, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
erranbe

Total Points: 118
Total Questions: 95
Total Answers: 117

Location: Virgin Islands (U.S.)
Member since Tue, Jul 7, 2020
4 Years ago
;