4

I am trying to increase the size of my history in bash. I have the following in my ~/.bash_profile

# Control the command history
export HISTFILESIZE=10000
export HISTSIZE=10000
export HISTCONTROL=ignoredups:erasedups
But, when I echo $HISTSIZE I always get 50. Am I missing something? Is there some command that my sys admin put in a higher config file that could prevent HISTSIZE from being changed?

4
  • What happens when you echo $HISTSIZE immediately after you export it? Do you still get 50 in that instance?
    – Dunnie
    Mar 30, 2011 at 14:23
  • @Dunnie Good question. ~$ echo $HISTSIZE 50 ~$ export HISTSIZE=100 ~$ echo $HISTSIZE 100 ~$ So I can set the HISTSIZE on the command line, but not in my .bash_profile.
    – jlconlin
    Mar 30, 2011 at 14:59
  • And do you get the same output if you place the echo in your .bash_profile? I'm basically trying to determine if your .bash_profile just isn't setting it at all, or if it's getting overwritten later on down the line.
    – Dunnie
    Mar 30, 2011 at 15:07
  • @Dunnie Yeah, you were right. One of those files sources something that changes HISTSIZE. I have changed the order of the sourcing of files and now it works. Thanks for your help.
    – jlconlin
    Mar 30, 2011 at 17:23

5 Answers 5

6

Many distributions seem to have .bash_profile check .bashrc somewhere inside of it. Could your .bashrc be sourced sometime later and set a HISTSIZE of 50?

2
  • I have checked .bashrc and (on this system) .bashrc.local; both are called after .bash_profile, neither contain anything about HISTSIZE.
    – jlconlin
    Mar 30, 2011 at 14:59
  • 2
    Does your .bash_profile (or any descendants) source any other files? /etc/profile might also be a culprit. Mar 30, 2011 at 15:25
5

What is your OS and BASH version? try

echo $BASH_VERSION

I use 4.2.20(2)-releasevia Mac OS X Lion / Homebrew... Here is my config

export HISTIGNORE="ls:ll:cd:pwd"
export HISTFILESIZE=3000
export HISTSIZE=3000
export HISTCONTROL=ignoredups:erasedups
export HISTTIMEFORMAT="[$(tput setaf 6)%F %T$(tput sgr0)]: " # colorful date

Try to update you bash. Also, maybe ~/.bashrc or /etc/bashrcor /etc/profile is overriding your local settings...

1

Your ~/.bash_profile may not be executing, or it there is a script later that is overriding the value. You can add some echo bash_profile statements to check.

Usually, these bash variables are defined in .bashrc, so you can try moving it there.

Also, don't use export with the HIST* variables. They are not environment variables, they are bash variables. Exporting them is useless. That's why putting them in /etc/environment doesn't do anything.

0

Try setting the variables in /etc/environment.

3
  • Putting HISTSIZE=5000 or HISTFILESIZE=5000 in /etc/environment does nothing for me. I'm in Arch Linux.
    – trusktr
    Oct 4, 2012 at 4:54
  • Oh, wait, putting the variables in ~/.bashrc or /etc/bash.bashrc works.
    – trusktr
    Oct 4, 2012 at 5:46
  • It works, but it seems to require me to login again? Because I have a proof that nothing has changed, because cat ~/.bash_history | wc -l gives a clear 2000, which is the default - and I have set about twice as much. From bash manual it states: "The shell sets the default value to the value of HISTSIZE after reading any startup files." Maybe, but it will NOT expand a .bash_history file that already exists. It stays at the default of 2000 lines. So before trusting bash, you should execute the above line to know it isn't trying to fool you. Dec 9, 2014 at 20:38
0

Regarding a few comments saying something was overriding my environment variable, I nullified this claim by trying set commands from the command line. I tried set HISTSIZE 9999 & set HISTSIZE=9999, and HISTSIZE remained echoing at 2000.

Then I tried export HISTSIZE=9999 and it stayed at 9999!

I gotta get my bash syntax down right :/

The takeaway is to call: export HISTSIZE=9999

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .