LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-04-2009, 09:03 AM   #1
rodent
LQ Newbie
 
Registered: Jul 2009
Distribution: Ubuntu Desktop 8.04 x64
Posts: 18

Rep: Reputation: 0
Changing bash history size


Hi,

I've tried reading man pages and googling to answer this and ended up wanting to kill myself. Trying to do things on Linux (in this case, Ubuntu) makes me feel that way every day.

So, my question: how do I change the size of my .bash_history file? I just want it to store 20000 lines instead of the default 500. And - do profiles affect in any way the way command history behaves?

Thanks,
R.
 
Old 08-04-2009, 09:06 AM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,950
Blog Entries: 5

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
The bash man page has this:

Quote:
HISTFILESIZE
The maximum number of lines contained in the history file. When this variable is assigned a value, the history file is truncated, if necessary, by removing the oldest entries, to contain no more than that number of lines. The default value is 500.
The history file is also truncated to this size after writing it when an interactive shell exits.
That is a variable you set at command line or can add to your bash_profile or .bashrc
e.g.
export HISTFILESIZE=1000

Last edited by MensaWater; 08-04-2009 at 09:45 AM. Reason: mistyped HISTFILESIZE as HISTFILE as pointed out by Jay73
 
Old 08-04-2009, 09:17 AM   #3
jay73
Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
Careful, histfile is not the same thing as histfilesize.
 
Old 08-04-2009, 09:45 AM   #4
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,950
Blog Entries: 5

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
Quote:
Originally Posted by jay73 View Post
Careful, histfile is not the same thing as histfilesize.
Fixed it - thanks for catching that - I just mistyped it.
 
Old 08-04-2009, 09:47 AM   #5
rodent
LQ Newbie
 
Registered: Jul 2009
Distribution: Ubuntu Desktop 8.04 x64
Posts: 18

Original Poster
Rep: Reputation: 0
So, I need to add the line
Quote:
export HISTFILE=1000
to ~/.bashrc ?
Or run 'export HISTFILE=1000' (or 'export HISTFILESIZE=1000') from a terminal, assuming it will change the setting permanently?
And how do Terminal profiles interact with history? Do they all share the same .bash_history file, or is there a separate one for each profile? I'm launching my terminal as follows: gnome-terminal --window-with-profile=c --geometry=170x50.
(I actually had to guess and experiment with '--geometry' because all the gnome-terminal manpage had to say on this option was a paraphrase on "go search....".)

Thanks, and sorry about being so dramatic before.
It's my frustration speaking, not me....

R.
 
Old 08-04-2009, 10:04 AM   #6
rodent
LQ Newbie
 
Registered: Jul 2009
Distribution: Ubuntu Desktop 8.04 x64
Posts: 18

Original Poster
Rep: Reputation: 0
Hi,

I added:

Quote:
export HISTFILESIZE=20000
shopt -s histappend
to ~/.bashrc

It worked!
Found those lines in ~/.bash_profile.
Edit: and, apparently, all profiles share the same history file.

Thanks,
R.

Last edited by rodent; 08-04-2009 at 10:05 AM.
 
Old 08-04-2009, 12:21 PM   #7
Ajit Gunge
Member
 
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253
Blog Entries: 1

Rep: Reputation: 21
question related to .bashrc

HI after doing hte changes suggested in this thread my .bashhistory should contain maximum 20000 commands isnt it
 
Old 08-04-2009, 02:08 PM   #8
rodent
LQ Newbie
 
Registered: Jul 2009
Distribution: Ubuntu Desktop 8.04 x64
Posts: 18

Original Poster
Rep: Reputation: 0
What I posted in my last post works on Ubuntu.
Bash will keep appending commands to ~/.bash_history until it reaches 20K lines, at which point for each new command added the oldest one at that moment will be removed.
 
Old 09-12-2009, 10:08 PM   #9
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS
Posts: 1,249

Rep: Reputation: 53
Code:
shopt -s histappend
Can I ask what this does?

Also the history command is not displaying all of the links in .bash_history???
Code:
root@server [~]# cat .bash_history |wc -l
1601
root@server [~]# history | wc -l
1000
What gives?

Last edited by abefroman; 09-12-2009 at 10:12 PM.
 
Old 09-14-2009, 10:13 AM   #10
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,950
Blog Entries: 5

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
I believe history in bash is buffered and not written to the history file until you exit the session.
 
Old 09-14-2009, 10:27 AM   #11
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS
Posts: 1,249

Rep: Reputation: 53
Quote:
Originally Posted by jlightner View Post
I believe history in bash is buffered and not written to the history file until you exit the session.
That is true, but I logged back out and then back in, the history command is only displaying 1000 lines by default.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash history delete command from bash itself ashishag Linux - Software 6 05-02-2010 03:39 AM
bash history file size iamback Linux - General 3 09-04-2007 12:32 PM
Changing history linux_dummy Linux - General 1 03-17-2006 02:36 AM
History Size reply2vinay Linux - Hardware 1 08-22-2005 06:36 AM
Changing Text Size/Terminal Width in Bash TastyWheat Linux - General 2 11-02-2003 11:24 PM


All times are GMT -5. The time now is 12:28 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration