Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't save current bash session to history

Tags:

bash

I notice that when opening .bash_history that it contains only the entries from my previous session, it seems that the current session is appended only on exit. Is there any way to prevent the current session from saving? Even crashing bash is an option if one knows how to do that. I found that I can kill -9 the process, but if there is a better way I would love to know.

like image 265
dotancohen Avatar asked Jan 27 '12 19:01

dotancohen


People also ask

How do I turn off bash history?

How to permanently disable bash history using set command. Again add set +o history to the end of to a new /etc/profile. d/disable. history.

How do I keep my bash history across sessions?

You probably want to tell bash to not overwrite the history each time, but rather to append to it. You can do this by modifying your . bashrc to run shopt -s histappend . You can also increase the size of your history file by exporting HISTSIZE to be a large-ish number (it's in bytes, so 100000 should be plenty).

Should you clear bash history?

It is important to note that bash shell does not immediately flush history to the bash_history file. So, it is important to (1) flush the history to the file, and (2) clear the history, in all terminals.

Why does bash history disappear?

This happens if the computer is "slow" while reading/writing parts of the history. Basically how it works is that your currently history is read, the file is deleted/moved away, and a new file is created, where all the history lines are written to.

How do I clear the history of a bash session?

Type the following command to clear the Bash history of the current session only: Put a space in front of your command and it won’t be saved in the Bash history. Unsetting HISTFILE will cause any commands that you have executed in the current shell session not to be written in your bash_history file upon logout:

Is Bash history saved when terminal session is closed in Ubuntu?

I recently replaced my Ubuntu 14.04 installation with Ubuntu Gnome (which comes with Gnome DE). But I noticed that bash history is not saved once the terminal session is closed. Once I close a terminal session and open a new one, and run the command history it does not show anything other than the history command itself.

Why can't I See my History in Bash_history?

It may be that your .bash_history doesn't belong to your user. Check the permissions of the file and if you're not the owner, change it: to check weather histappend command is 'on' or 'off' If it is off then type following command to append history If you want to save history with every new prompt run following command

How do I save Bash history manually?

To save bash history manually to a file: history -w ~/history.txt vim ~/history.txt It exports the history to a file called history.txt. You can then view it using your favorite editor.


1 Answers

Unset the $HISTFILE variable

$ unset HISTFILE 

If HISTFILE is unset, or if the history file is unwritable, the history is not saved.
http://www.faqs.org/docs/bashman/bashref_106.html

like image 67
user123444555621 Avatar answered Oct 14 '22 00:10

user123444555621