There is a little misunderstanding here,
history does not show the content of
~/.bash_history. Instead, it shows the current content of Bash's history list in memory for this session.
Assuming a default setup of Bash and Ubuntu, the history management works as follows:
Whenever you open a Bash shell, it will read in the content of your
.bash_history file and append that to its session history list.
You type in commands, causing Bash to append them to its session history list.
When you close your shell again, Bash will save its history list to the disk by appending the contained entries to your
Note: by default the history list gets truncated to at most 1000 entries, and the history file to 2000 entries.
You see, the history file will never get updated until the specific shell session ends, so everything you did in your current terminal window is not persisted to the disk yet. It resides only in your history list in memory.
To clear a specific entry from your history list, you can run
history to display the full list and find out the index number of your offending entry. Then you can delete it using
history -d NUMBER
You can also simply wipe your complete session history list using
Note that deleting an entry from the history list does not automatically delete it from
.bash_history if it got already written there, but neither does deleting an entry from the file remove it from your current session history list, if you have any Bash sessions open.
To delete an entry from the history file, open your
~/.bashrc in a text editor and delete the offending line there. You should either close all terminal before that and use a GUI editor, or make sure you remove the entry from both the file and the session lists.
For more information about the
history command, type
More information about Bash and its history management, read the relevant parts of