How to delete a single command from history on a Linux/Unix Bash shell

Originally published at:

I’m working in Ubuntu bash terminal application and remotely on a RHEL server in cloud platform. I typed the wrong and dangerous command which I no longer wish to remember. How do I get rid of dangerous command in the history file? How can I remove or delete a single command from bash history file?

I assume you’re using the very common bash command interpreter.
So, you simply need to edit your ~/.bash_history file, using any editor you are familiar with (be it the vi, or the internal editor in mc, etc), search for that command and remove it from the file; and, of course, save the file.
Occasionally, I do this thing myself on my Opensuse box (mostly to make sure certain commands I need to repeat are kept at their numbered position, so as to re-call them using the !cmd_number shortcut :slight_smile: )