The bash terminal commands history for a user is stored in $HOME/.bash_history
file. The commands used in the tty
session will be written to the .bash_history
file when the tty
session is terminated; but running history -c
command will prevent them from being appended in the history file. What history
command does is it displays the contents of the $HOME/.bash_history
. (You can also check and/or edit the file with text editors, say with nano $HOME/.bash_history
.)
"A command with a space before it won't be stored.., !!
or duplicate commands won't be stored, etc."
You can change the settings according to your needs by making changed in $HOME/.bashrc
file. This post explains how: Get bash history to remember only the commands run with space prefixed!.
And in this file you may find lines like:
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
HISTSIZE is the number of commands to remember in the command history. The default value is 500
.
HISTFILESIZE is maximum number of lines contained in the history file. When this variable is assigned a value, the history file is truncated, if necessary, by removing the oldest entries, to contain no more than that number of lines. The default value is 500
. The history file is also truncated to this size after writing it when an interactive shell exits.
So, to summarize history -c
just clears the running tty
session's history and the previous commands should still be accessible with history
command provided the older commands are not truncated as per the HISTFILESIZE <= max_lines constraint.
sudo !!
command also wouldn't be stored in the history.