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

www.l‮uttua‬ri.com
How to delete a single command from history on a Linux/Unix Bash shell

To delete a single command from the history on a Linux or Unix Bash shell, you can use the history command followed by the -d flag and the line number of the command you want to delete. The history command displays a list of the commands that have been entered in the current Bash session, and the -d flag allows you to delete a command from the history list.

For example, to delete the fifth command from the history list, you can use the following command:

$ history -d 5

To view the history list and find the line number of the command you want to delete, you can use the history command without any flags:

$ history
1  ls
2  cd documents
3  vi file.txt
4  cat file.txt
5  rm file.txt
6  history

In this example, the fifth command is rm file.txt, so you can delete it by running history -d 5.

Note that this will only delete the command from the history list in the current Bash session. If you want to permanently delete the command from the history file, you will need to edit the ~/.bash_history file.

Created Time:2017-10-28 21:39:01  Author:lautturi