November 6 2016

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 ####



Copyright 2020. All rights reserved.

Posted November 6, 2016 by Timothy G in category "Admin Tools", "Linux

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.