-1

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 .

Megan Fox
  • 435
  • 2
  • 6
  • 20
  • What about `rm ~/.bash_history`? – Andreas Louv Jun 06 '16 at 08:54
  • do you wanna get rid of all history commands ? – Rahul Jun 06 '16 at 08:57
  • All will be fine but am curious to know if can be done for any specific dates or time? – Megan Fox Jun 06 '16 at 09:00
  • Use: [`vim ~/.bash_history`](https://www.facebook.com/photo.php?fbid=10152204120002323&set=a.10150339989232323.397391.628937322) to [selectively delete lines](http://stackoverflow.com/questions/5362363/vim-how-to-delete-a-large-block-of-text-without-counting-the-lines) you don't want... – anishsane Jun 06 '16 at 09:33
  • Also, if you happen to copy-paste a chunk of lines on terminal (this itself is a security risk, but anyway, you have already done that error...) & you don't want the history to be written to file, set [`HISTFILE=/dev/null`](https://www.gnu.org/software/bash/manual/html_node/Bash-History-Facilities.html) – anishsane Jun 06 '16 at 09:37

1 Answers1

3

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.

Nishu Tayal
  • 20,106
  • 8
  • 49
  • 101