17

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

15

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.

8

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.

  • 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? – Dr Beco Apr 15 '17 at 0:23
7

@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

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.