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

To delete a single command from the history in a Linux/Unix Bash shell, you can use the “history” command to view the command history, and then use the “history -d” command to delete a specific command by its number.

Here’s an example:

  1. View the command history using the “history” command:
history
  1. Find the number of the command you want to delete from the list of commands displayed.
  2. Use the “history -d” command to delete the desired command, replacing “N” with the number of the command:
history -d N

Note that after you delete the command from the history, it will no longer be available for recall using the “history” command or the “up arrow” key. However, the change to the history will only persist for the current session. If you log out and log back in, the history will be reset to its original state. To make the change permanent, you will need to update the “~/.bash_history” file or configure the Bash shell’s history settings.

Leave a Comment