Clear your Linux History | Snippet | Linux
There’s only a few times where I’ve decided I needed to clear out my bash history without a trace, typically it was because I needed to test sending to a mail provider but didn’t want to leave my email there, or I saw that the customer pasted his password into the command line with things like “mysql -uroot -pmypassword”.
For those jobs where I need to clear out a whole batch of lines:
for i in {1..50}; do history -d $((HISTCMD-1)) && history -d ####; done
That script there will clear out 50 lines, starting from whereever you set ####. So if you run “history” and you see that you need to clear from lines 350 – 380, you’ll run:
for i in {1..30}; do history -d $((HISTCMD-1)) && history -d 350; done
If you just want to delete a certain line:
history -d $((HISTCMD-1)) && history -d ####