Ubuntu – Stop Terminal from saving commands

16.04command linesystem

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)

Best Answer

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:

#!/bin/bash
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.