Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-29-2007, 06:03 AM   #1
Registered: Jun 2005
Posts: 374

Rep: Reputation: 30
Retaining Bash history from all sessions

I've noticed that when I have many sessions open, the history from one closed session will overwrite the history from another earlier closed session so that when I open a new session I only see the history of the most recently closed session.

Is there a way I can merge/retain all Bash history from all sessions?

I was thinking about something in the .bash_logout, perhaps a func to merge the histories, appending only the new lines to the history file, but the problem is that the history numbering overlaps, so this could be tricky.

Another question would be how Bash handles the history, is it before or after the processing of the history file? If it's after, then would bash just overwrite the history file with the current session history regardless of what is in .bash_logout?

Any Ideas?
Old 11-29-2007, 07:39 AM   #2
LQ Guru
Registered: Oct 2003
Posts: 5,062

Rep: Reputation: Disabled

note that I am a fan of having zero history on reboot I touch a new file to stop intruders reading certain things
Old 11-29-2007, 08:16 AM   #3
Registered: Jun 2005
Posts: 374

Original Poster
Rep: Reputation: 30
yes I tried this no history for a while too but the inconvenience outweighs the small security I think.

thanks for the link, looked too basic to start, but they mention history -a which I have found elsewhere as a possible solution...
Old 11-29-2007, 04:22 PM   #4
LQ Guru
Registered: Oct 2003
Posts: 5,062

Rep: Reputation: Disabled
open a shell command
info bash

has more juicy stuff
Old 11-29-2007, 05:38 PM   #5
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,041
Blog Entries: 11

Rep: Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907
Here's the history relevant part from my ~/.bashrc
# handle history file gracefully for multiple windows open
shopt -s histappend
export PROMPT_COMMAND='history -a'
# 'normal' history stuff
export HISTFILESIZE=6000
export HISTSIZE=2000
export HISTCONTROL=ignoreboth
# and things I don't want to see in my history (ever)
export HISTIGNORE="*PROMPT*:lsc:cd:cd ..:pwd:exit:mc:clear:history *:cd \"\`echo *:ps -A:top:./configure --help:locate:fj"



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
LXer: Keeping Command History across Multiple Sessions LXer Syndicated Linux News 1 11-07-2007 10:58 AM
Where's my bash history? subnet_rx Red Hat 6 02-07-2007 06:35 PM
need someone to look into this bash history bytez Linux - General 7 10-16-2006 10:26 PM
bash history jasonnth Linux - Software 7 08-08-2006 01:35 AM
bash history slowly Linux - General 2 11-12-2004 11:35 AM

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

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