Removing a range of history lines from bash history


You would like to remove some lines from the bash history (ie using cut and paste with wrong values).


You can use the following, taken from the answer here

for i in {1..no_of_lines}; do history -d start_line; done

where start_line is the start of the lines you want to remove and no_of_lines is the number of lines you want to be removed.

Remove line from bash history


You want to remove a certain line from your server’s bash history, if for example you pasted a password in the wrong place.


Use the two steps:

1. history -d line_number to remove from memory
2. history -w to write in-memory history to the history file ~/.bash_history

as described here

When the shell is not bash (sh) you can remove them from ~/.ash_history and then source the file.