How to set per session history
From Wiki-UX.info
Abstract
This procedure applys for users using the "sh" and "ksh" shells.
Update "/etc/profile" file
Add the following piece of code on /etc/profile file. This will create a separate directory for each terminal (physical or virtual) of each user that logins using "sh" or "ksh" shells. Inside those directories, individual command history files named by the terminal will keep track of the session commands.
... # Setup a shell history file specifically for this tty TTY=$(tty) echo "You are logged on with tty" $TTY FILE=$(echo $TTY | sed 's/\/dev\///' | sed 's/\//_/g') if [ ! -d ~/.sh_history ] ; then mkdir -p ~/.sh_history fi export HISTFILE=~/.sh_history/$FILE > $HISTFILE unset FILE export HISTSIZE=256 # End shell history setup
Another option is to setup a history file based on the source of the connection.
... # SETUP HISTORY FILE export PS1="$(whoami)@$(hostname):> # " FILE=$(who am i -u | awk '{print $NF}') if [ ! -d ~/.sh_history ] ; then rm ~/.sh_history mkdir -p ~/.sh_history fi export HISTFILE=~/.sh_history/$FILE export HISTSIZE=256 unset FILE # SETUP HISTORY FILE
Reference
Authors
- Editor Scott Marer