In terminal the bash history is often helpful when you are searching for a command-line that you already used. But is there a way to influence the behavior of the bash history (i.e. which commands are saved, how long they are saved, how many are saved and so on)?
Several variables control the behaviour of your history:
HISTCONTROL: controls how values are saved in your history. The values
erasedupscan entered here (separate them by colon).
HISTFILE: sets the location of the history file.
HISTFILESIZE: sets the maximum number of lines in your history file.
HISTIGNORE: has a list of pattern which the bash ignores (see the other answer for syntax).
HISTSIZE: contains a number of lines which are remembered in the actual shell.
HISTTIMEFORMAT: contains an expression how an entry is formatted (see other answer)
Setting timestamp for history:
By default, history do not append with timestamp, but it is easy to configure it to display timestamp, you just need to set one environment variable HISTTIMEFORMAT.
export HISTTIMEFORMAT="%h/%d - %H:%M:%S "
- Execute history again to see the result.
If you dont want to save the commands in history,then
- HISTFILE - Controls where the history file gets saved.
- HISTFILESIZE - Controls how many history commands to keep in HISTFILE.
- HISTSIZE - Controls how many history commands to keep in the history list of current session.
- HISTIGNORE - Controls which commands to ignore and not save to the history list.
- You will loss your settings once you close your terminal.So if you want it to have permanently then you should add the above command to
You could add a line like
~/.bashrc to increase the size of the history. By default commands started with a space are not saved. That is due to the
export HISTCONTROL=ignoreboth that is globally enabled in ubuntu by default.
You can also ignore commands starting with
which by using
There is a way to tell history NOT to remember a command: just start with a space. There is also a very easy way te retrieve a specific command: type CTRL+R and a word from the command you are searching for.
There is certainly a way to increase the default history which is 500 lines by defaults... but I don't know how, sorry!