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)?

  • Hi! You may look man history up, then ask a concrete question! :) – antivirtel Dec 25 '10 at 19:50

Several variables control the behaviour of your history:

  • HISTCONTROL: controls how values are saved in your history. The values ignorespace, ignoredups and erasedups can 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. alt text
  • If you dont want to save the commands in history,then

    export HISTSIZE=0


  • 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 ~/.bashrc or ~/.bash_aliases.

You could add a line like

export HISTFILESIZE=5000

to your ~/.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 l or which by using

export HISTIGNORE="l*:which*"

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!

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.