Re: Common History across Shell



On Jul 10, 1:36 pm, quarkLore <agarwal.prat...@xxxxxxxxx> wrote:
AFAIK history in bash is implemented such that each bash instance
maintains its individual history in memory. As and when a bash session
exits it updates history file.

If there are multiple shells running together then commands entered in
one can't be accessed using history command from other shells.

I am looking for a feature where if a user has multiple shells and on
a special keystroke / command all shells get a common history which is
sum of all histories.

Does such a feature exist in bash or any other shell?
Can such a feature be implemented without changing the shell's code?

Yes. That is precisely what bash appears to be doing. .bash_history is
opened in read only mode and appends the commands to the file when
bash exits.

[root@braveheart]# truss -t open bash
open("/var/ld/ld.config", O_RDONLY) Err#2 ENOENT
open("/lib/libcurses.so.1", O_RDONLY) = 3
open("/lib/libsocket.so.1", O_RDONLY) = 3
open("/lib/libnsl.so.1", O_RDONLY) = 3
open("/lib/libdl.so.1", O_RDONLY) = 3
open("/lib/libc.so.1", O_RDONLY) = 3
open64("/dev/tty", O_RDWR|O_NONBLOCK) = 3
open("/proc/2546/psinfo", O_RDONLY) = 3
open64("/var/run/name_service_door", O_RDONLY) = 3
open64("/root/.bashrc", O_RDONLY) = 4
open64("/root/.bash_profile", O_RDONLY) = 4

open("/usr/share/lib/terminfo//x/xterm", O_RDONLY) = 4
open64("/root/.bash_history", O_RDONLY) = 4
open64("/root/.bash_history", O_RDONLY) = 4

open("/usr/share/lib/terminfo//x/xterm", O_RDONLY) = 4
[root@braveheart]# exit
exit
open64("/root/.bash_history", O_WRONLY|O_APPEND) = 4
open64("/root/.bash_history", O_RDONLY) = 4
open64("/root/.bash_history", O_WRONLY|O_TRUNC) = 4
[root@braveheart]#

There is no syncing of bash_history that happens if you have multiple
shells which are run by same user. I have verified that

.



Relevant Pages

  • Re: bash history search key binding
    ... maybe your bash history was accidentally reset.. ... or lost its cd* commands .. ... will display the cd commands in your current history.. ... Maybe I should try reassigning the backward search command to CTRL-R for a while and see if it has any limitations that I didn't notice while experimenting.. ...
    (Debian-User)
  • Re: how can I write shell history immediately to HISTFILE
    ... The bash internal command "history" can be told to append ... This will append every new command to the history file, ... Lots of times I notice commands are not present that I thought should ... Read the bash manpage and look up HISTCONTROL. ...
    (comp.unix.shell)
  • RE: save commands history.
    ... > the commands ... >> from that login sessoin. ... bash will write the command history ... wrapper around bash to not use the history -c or else to output ...
    (RedHat)
  • Re: logging
    ... >> Usually bash writes the commands to its history file no matter ... >> which tty it is runing on. ... >> commands in the history. ...
    (comp.os.linux.security)
  • Re: Help with a little dd damage!
    ... (No output, just bash history.) ... Today I ran these commands: ... So restoring ...
    (Fedora)