Is there any command that I could use that makes .bash_history never clear itself? After a certain amount of commands it just clear itself.

I think this works but I'm not sure?


I did run this but I'm not sure if it does what I asked.

And I know that if the file gets too big then bash might be slower, but I'll just move it out every now and then.


Add this line to your .profile (or .bash_profile):

export HISTSIZE=

From Bash History Facilities documentation:

If HISTFILESIZE is not set, no truncation is performed.

  • 1
    +1, I didn't know we could leave it unset! I suggest you add the lines to ~/.profile not ~/.bashrc though. – terdon Nov 9 '14 at 17:31
  • @terdon: I think .profile is for thing that is not specifically related to bash, HISTSIZE and HISTFILESIZE are very related, so .bashrc is more suitable. – cuonglm Nov 9 '14 at 17:38
  • Well, yes and no. You can always use ~/.bash_profile to make it bash-specific. The point is that .bashrc is read each time a new non-login shell is started so having env variables set there makes them be re-read for every shell which is not elegant. Still, you're right about this causing issues with other shells. In any case, you will need to also add them to .profile (or another file that is read by login shells) else the history file will get truncated each time a login shell is started. See BASH history truncated to 500 lines on each login – terdon Nov 9 '14 at 17:42
  • @terdon: Good point, updated my answer. – cuonglm Nov 9 '14 at 17:50
  • But if i type 100000 it will still get cleared after 100000 (bytes, commands whatever) right? – DisplayName Nov 9 '14 at 18:31

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.