Megan Fox Megan Fox - 5 months ago 15
Linux Question

Delete bash history in Centos 6.2

I accidentally copied a huge block of text into my Centos6.2 shell and it's annoying me in my bash history, how can I delete it?

I tried to run

history -d {{ number }}
but it comes back the next time I open a shell :(

Additionally when I tried using
history -d $i
in a for i in list loop
, I don't think it deleted anything as they run in subshells .

Answer

You can use following command to clean the .bash_history file:

history -w 
history -c

And to delete a particular line, use following:

history -d <line_number> // deletes the line from history in memory

history -w will write the current in-memory changes to .bash_history file.

Comments