Command Line History – How to Have Separate Command History for Different Sessions for the Same User

command historycommand linekshtcsh

I face this issue on some of Unix servers. When I open different session for same user, command history is shared by all the session. This creates issues if by mistake I press Ctrl-P or up arrow and just press Enter.
On one occasion I end up running rm -rf * thankfully I was in directory where I don't have permissions to remove files.

How to have separate command history for different sessions for the same user?
Most of the time I am using ksh and tcsh shells.

Best Answer

From the ksh faq:

Q1. How do I get separate history files for shell?

A1. ksh uses a shared history file for all shells that use the same history file name. This means that commands entered in one window will be seen by shells in other windows. To get separate windows, the HISTFILE variable needs to be set to different name before the first history command is created.

Related Question