Deleting history from ~/.bash_history

Solution 1:

  1. You just forgot the preceding dot, the command to open your (bash) terminal history file is

    gedit ~/.bash_history
    

    This file is only updated when you close a terminal.

  2. To remove the last 10 lines from this file and don't get this command itself recorded, open a new terminal and execute the following chain of commands:

    sed -n -e :a -e '1,10!{P;N;D;};N;ba' ~/.bash_history && history -c && exit
    

    or

    for i in {1..10}; do sed -i '$d' ~/.bash_history; done && history -c && exit
    

    or

    head -n -10 ~/.bash_history > ~/.b_h_2 && mv ~/.b_h_2 ~/.bash_history && history -c && exit
    

    sed or head respectively deletes the selected lines from ~/.bash_history, history -c clears the terminal's history and exit closes it.

Solution 2:

The bash_history file is a hidden file, starting with a dot. You need to do

gedit ~/.bash_history

This will open up the file in gedit.

Solution 3:

If you want to delete only certain parts of your command log then the above methods are just fine. If you want to stop command logging for a particular bash session, then issue the command

unset HISTFILE

To be more drastic, if you don't want any of your commands to be logged, then you can do

rm ~/.bash_history
ln -s /dev/null ~/.bash_history

Note that the first method would be in effect only for a single session, whereas the second method would stop command logging for all future sessions.