tag:blogger.com,1999:blog-8032022811235182759.post9032444519094556887..comments2024-03-23T08:25:23.254-07:00Comments on Linux Commando: Keeping Command History across Multiple SessionsPeter Leunghttp://www.blogger.com/profile/05589860210899238688noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-8032022811235182759.post-67720158016983500792015-12-20T03:32:26.719-08:002015-12-20T03:32:26.719-08:00Thanks for sharing.Thanks for sharing.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-78532574073478424152014-06-02T21:02:45.778-07:002014-06-02T21:02:45.778-07:00Hi,
I ended up solving this problem by writing a s...Hi,<br />I ended up solving this problem by writing a script called hiset, it basically just automates the <br /> history -a<br /> export HISTFILE="$1"<br /> history -r $HISTFILE<br />But provides functionality to list view and search all existing history files along with tab completion.<br />I have written about it on my blog: http://simotek.net/tech/hiset-multiple-history-files-and-sessions-for-bash-and-other-tinkering/<br />and the source is avalible https://github.com/simotek/scripts-configSimonhttp://simotek.netnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-26224684954473507922013-12-24T16:21:35.878-08:002013-12-24T16:21:35.878-08:00very handy, thanks a lot.very handy, thanks a lot.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-83661933266134848462012-12-05T13:37:41.661-08:002012-12-05T13:37:41.661-08:00i have something cleaning up my history every logo...i have something cleaning up my history every logon, no idea what.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-66085731744823236772012-08-31T20:48:57.649-07:002012-08-31T20:48:57.649-07:00The PROMPT_COMMAND posted by dc46and2 *almost* gav...The PROMPT_COMMAND posted by dc46and2 *almost* gave me what I needed, but I found each time I did a command then issued a 'history' command it kept adding all 1000+ entries into my current term history. Modifying the 'history -r' to 'history -n' did it for me. I also want to point out that the spaces between the semicolon and the command that follows is important. I was getting errors after each command I entered until I added spaces. THANKS dc46and2! I FINALLY have what I wanted!!!meathead9999noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-15735938004221082092012-08-02T17:59:30.378-07:002012-08-02T17:59:30.378-07:00Thanks for the useful post. The issue Dave E poin...Thanks for the useful post. The issue Dave E pointed out seems to be due to the fact that each bash session reads the history file at shell initialization and thereafter maintains its own copy of history in memory. The 'history -a' command will update the history file after every command, but it doesn't affect the in-memory history of other running shells.<br /><br />You can force the current shell to reread the history file with 'history -r'. Run that manually when you want to use or view history from other sessions, or use<br /><br />PROMPT_COMMAND="history -a; history -r; $PROMPT_COMMAND"<br /><br />Remember the PROMPT_COMMAND is only executed <i>after</i> a command, so you will have to execute a command or just hit enter to pull in the history generated by other shells since the last command in the current shell.dc46and2https://www.blogger.com/profile/11838086302149952789noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-55218653046687866452012-02-02T21:34:53.057-08:002012-02-02T21:34:53.057-08:00@Jesus Carretero - Dave E is correct but only *bec...@Jesus Carretero - Dave E is correct but only *because* he didn't read the blog accurately. <br /><br />History is written to on *session exit*. He is looking for real time history write as each command is written. <br /><br />Peter Leung's post is not a 'good try' it is an accurate statement of how to do exactly what he says.Stevenoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-23319927260906305382010-05-27T08:50:29.906-07:002010-05-27T08:50:29.906-07:00Dave E is very right. PETER LEUNG doesn't keep...Dave E is very right. PETER LEUNG doesn't keep command history across multiple sessions due to the problem described by Dave E.<br /><br />Good try. Thanks anyway.Jesus Carreterohttps://www.blogger.com/profile/04878241558919132468noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-16106383071665801352009-07-08T03:45:31.038-07:002009-07-08T03:45:31.038-07:00Your solution ignores the setting HISTIGNORE, so I...Your solution ignores the setting HISTIGNORE, so I see a lot of duplicates ( which I used to avoid via HISTIGNORE )<br /><br />I now have the following in my .bashrc<br /><br />_archive_history ()<br />{<br />history -a<br />}<br /><br />trap _archive_history EXIT<br /><br />If I now exit my xterm's only the changes from those sessions are recordedUnknownhttps://www.blogger.com/profile/16531849129112222379noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-31971401560375514472009-06-25T09:00:50.804-07:002009-06-25T09:00:50.804-07:00I followed the instructions, and I see that my pro...I followed the instructions, and I see that my prompts from all sessions are being properly appended to $HISTFILE. However, I think that my 'history' command is not taking the recent $HISTFILE entries into account from the other sessions.<br /><br />For example, things start out synchronized when I open the two sessions:<br /><br />(open session1)<br />(open session2)<br /><br />[session1]: history<br /> 498 ls<br /> 499 exit<br /> 500 exit<br /> 501 history<br /><br />[session2]: history<br /> 498 ls<br /> 499 exit<br /> 500 exit<br /> 501 history<br /><br />But if I run some commands in one session, they don't appear in the 'history' of the other session:<br /><br />[session1]: echo 1<br />[session2]: echo 2<br /><br />[session1]: history<br /> 500 exit<br /> 501 history<br /> 502 echo 1<br /> 503 history<br /><br />[session2]: history<br /> 500 exit<br /> 501 history<br /> 502 echo 2<br /> 503 history<br /><br />How do I make 'history' read the latest contents of $HISTFILE?Anonymoushttps://www.blogger.com/profile/05133927467176763193noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-44437005544637910132009-05-22T10:09:48.499-07:002009-05-22T10:09:48.499-07:00Any way to do it in Midnight Commander?Any way to do it in Midnight Commander?Alexey Torkhovhttps://www.blogger.com/profile/11513573296166139122noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-2798881842447263302008-12-18T00:30:00.000-08:002008-12-18T00:30:00.000-08:00ahhh thanks for that last bit, I was wondering tod...ahhh thanks for that last bit, I was wondering today why this wasn't working and it was because of thatmaehttps://www.blogger.com/profile/10879711379090472478noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-44720717005179287252007-11-09T12:17:00.000-08:002007-11-09T12:17:00.000-08:00I suspect that $PROMPT_COMMAND was null in the fir...I suspect that $PROMPT_COMMAND was null in the first place. Therefore, did not like it when you concatenate the new stuff.<BR/><BR/>To correct the problem:<BR/><BR/>1. First, clear the $PROMPT_COMMAND<BR/>unset PROMPT_COMMAND<BR/><BR/>2. Then set it<BR/>PROMPT_COMMAND='history -a'<BR/><BR/>I will make it clear in my blog post.<BR/><BR/>Sorry for the inconveniencePeter Leunghttps://www.blogger.com/profile/05589860210899238688noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-6218114748808332532007-11-09T02:12:00.000-08:002007-11-09T02:12:00.000-08:00Hi, Using bash in a virtual console, as I type the...Hi, <BR/>Using bash in a virtual console, as I type the second command, it complains :<BR/>bash: PROMPT_COMMAND: line 3: syntax error near unexpected token `;'<BR/>bash: PROMPT_COMMAND: line 3: `;history -a'<BR/>(line 3 'cos I echoed $HISTSIZE)<BR/>?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-63830967368119444352007-11-07T11:02:00.000-08:002007-11-07T11:02:00.000-08:00shopt is a built-in bash command.Which shell are y...shopt is a built-in bash command.<BR/><BR/>Which shell are you using?Peter Leunghttps://www.blogger.com/profile/05589860210899238688noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-92034573071776070882007-11-07T10:22:00.000-08:002007-11-07T10:22:00.000-08:00I don't have 'shopt' as a command. I couldn't find...I don't have 'shopt' as a command. I couldn't find it under apt-cache search, either.kuriharuhttps://www.blogger.com/profile/09466511969578138882noreply@blogger.com