When using terminal, it saves the previously executed commands. When I press the Up arrow button, it tells us that which commands I have run previously.

Suppose, I am using my friend's system and start using it's command-line. Now, my friend will get to know what commands I have been running. But I don't know want him to know this.

Is there a way I can stop terminal from saving these commands for the current session ?

(Just suppose this scenario for this question. I am not a cheater)

  • 2
    For a non persistent solution do the following in the terminal: unset HISTFILE
    – Carl
    Apr 6, 2017 at 13:09
  • 2
    " But I don't know want him to know this." If it is his system I consider this abuse of his system.
    – Rinzwind
    Apr 6, 2017 at 13:12
  • 2
    @Rinzwind: In my opinion it can be matter of privacy.
    – Ravexina
    Apr 6, 2017 at 13:19
  • 1
    @luv.preet: as a alternative to what carl said, you can use history -c before closing the terminal too.
    – Ravexina
    Apr 6, 2017 at 13:19
  • 1
    Examine the HISTFILE variable. It will remove this variable. Therefore it wouldn't be updated. Apr 6, 2017 at 13:19

1 Answer 1


Several things you could do.

1. Type a space in front of each command you run.

It's tedious, but putting a space in front of your commands will keep them from being saved to the bash history.

2. Set a Cronjob to delete .bash_history every hour

Your terminals historical commands are stored in .bash_history in your home directory. If you delete the file, it will effectively remove your history.

First create the script to remove the .bash_history file:

nano ~/script.sh

and add:

rm /home/user/.bash_history

then run:

chmod 775 script.sh

to make script executable and run:

crontab -e

and add 1 * * * * * /home/user/script.sh.

Then exit and save, and it should delete your history every hour.

3. Run unset HISTFILE, as @Carl suggested.

Just run it before exiting the terminal, and it will not save those commands that you ran in the last session to .bash_history.

  • 1
    It's probably worth distinguishing which solutions disable the collection of history (i.e. the commands would not be visible in the current session) versus disabling recording it to, or subsequently modifying the contents of, the history file. FYI you might want to consider adding set +o history / set -o history. Apr 6, 2017 at 14:12
  • typing a space is an easy thing, this will work. So, this does not let a command to be stored in history, right ?
    – luv.preet
    Apr 6, 2017 at 15:10
  • That's right. Just type a space in front of the command and try pushing the up arrow after running the command: you won't see anything.
    – anonymous2
    Apr 6, 2017 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.