The bash shell is a commonly used shell on Unix/Linux systems. The history feature which is available with the bash shell is very useful, allowing you to easily recall and reuse previously entered commands without retyping them. E.g., if you had entered a long ssh command with a lot of options, you can simply hit Ctrl-R and type
ssh
to recall the last ssh command entered. You
can then edit the command or simply hit Enter to execute the
same command again.
Occasionally, though, you may not want something you've typed at
the shell prompt to remain in your history file. E.g., I've occasionally
inadvertently typed a password at a point where a password prompt hadn't
appeared. You can delete a particular command by using history -d
num
where num is the number assigned to the command
in the history file, which you can see by typing history
with
no parameters. After deleting the command use history -w
to
write the update to your ~/.bash_history
file to disk.
E.g., If I saw that command 245 was showing the password I
mistakenly typed, I could use the following commands to ensure that
the password couldn't be viewed by anyone who might gain access to the
history information:
$ history -d 245 $ history -w
If you wished to delete all the commands stored in the history file, you
could use history -c
followed by history -w
.