Tuesday, January 18, 2011

Is it possible to have a unique .bash_history file per host?

My home directory is mounted on an NFS mount. The commands I use on one machine are usually quite different to those on another. Is it possible to have easy host write to it's own history file?

  • There is the environment variable HISTFILE, which controls where the history file is. You could try to create a login script that resets HISTFILE according to your hostname/IP.

    From Thilo
  • It certainly is. You just have to change the name of your history file on each host. In your .bash_profile put something like:

    export HISTFILE="${HOME}/.bash_history.`hostname`"
    
    brianegge : My bash wouldn't expand ~, so I had to use ${HOME} export HISTFILE="${HOME}/.bash_history.$(hostname)"
    Kamil Kisiel : Thanks, modified the answer.

0 comments:

Post a Comment