26

Can I increase the size of the command history in bash?

Note that I use a Red Hat Linux computer in the undergraduate astrophysics department here (so I don't get that many privileges).

InquilineKea
  • 6,262

3 Answers3

22

Instead of specifying numbers, you can do

unset HISTSIZE 
unset HISTFILESIZE
shopt -s histappend

in which case only your disk size (and your "largest file limit", if your OS or FS has one) is the limit.

However, be aware that this will eventually slow down bash more and more. see this BashFAQ document and the debian-administration article (original link died, look in a mirror: archive.is and archive.org) for techniques which scale better.

Philomath
  • 2,877
9

You can use logrotate to preserve old entries. It allows you, for example, to set size limits that will trigger archiving. It is normally run from a daily cronjob, but you might just as well invoke it from your .bash_logout script.

  • 2
    Looks like the most sustainable approach to me, since removing size limits will, on the long run, have performance impacts. While I'm not sur I'll reach the treshold anytime soon, I'm afraid it would take some time to start noticing such impacts. Btw, consider adding the config you set, and the optionnal bash logout command to add. – Balmipour Feb 27 '17 at 16:34
  • The link is down. Maybe edit to point to another link with the same intended info? – DrBeco Apr 15 '17 at 00:23
9

@Philomath, unsetting those environment vars does not work for me at all! For me, this causes bash to use its inbuilt defaults (it seems) of truncating .bash_history to about 9KiB.

What does work for me is the following in my .bashrc:

export HISTSIZE=
export HISTFILESIZE=
shopt -s histappend
zenaan
  • 336
  • That works? The manpage says for HISTFILESIZE: "Non-numeric values and numeric values less than zero inhibit truncation." and for HISTSIZE: "Numeric values less than zero result in every command being saved on the history list (there is no limit)." So, for clarity, it would seem best to set both to -1 (not blank), right? – Geremia Feb 21 '24 at 20:03