My history is 'polluted' with some specific lines that have typo's and such. For example: I often have to ssh to a certain server like so:
ssh [email protected]
> Connects succesfully
But I also make a typo sometimes:
ssh [email protected]
> Permission denied
Because I rely on history this typo is duplicated multiple times:
cat .zsh_history | grep [email protected]
> : 1510301683:0;ssh [email protected]
> : 1511166682:0;ssh [email protected]
> : 1511193552:0;ssh [email protected]
> : 1512730972:0;ssh [email protected]
> : 1516368993:0;ssh [email protected]
> : 1516802690:0;ssh [email protected]
> : 1519633368:0;ssh [email protected]
Is there an easy way to clean up my history purely by the results of the grep
-command? (or perhaps there's some other, more clever solution?)
Update:
Please note: I am not looking for a way to delete line x
from the history; I know there are plenty of articles out there that cover that. I'm simply looking for a (simple?) way to delete all lines that contain string y
.
x
. The linked question is how to delete by line numbers.grep
fix is in a comment by *mivk, which prints out the needed commands, (without actually running them):history | grep XYZ | grep -v grep | tac | awk '{print "history -d", $1}'