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.

4 Answers
4

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.

I'm assuming you are talking about simultaneous sessions; separating sessions that are after one another isn't very useful: you would never be able to use it's history anymore, because all sessions would be unique. If that were the case, you would probably be better off just disabling command history.

If we are talking about separating simultaneous session, I'd recommend you use Bash. I'm pretty sure I'm not getting the command history from two simultaneous sessions mixed with it. Bash only writes history to .bash_history at logout, so command history won't get mixed until after logout. Provided that using Bash is acceptable, would that solve your issue?

I cant install screen. its not even compiling on my server.
–
HemantAug 16 '10 at 10:51

I'm not sure how screen would give you that capability anyway
–
Michael Mrozek♦Aug 16 '10 at 13:26

@Michael you can have different sessions with screen and screen has it's own history. I dunno someone told me to solve my problem with screen... I didn't like screen. lame that this got downmodded when my second answer is essentially the same as the other ones that got upmodded. @Hemant ... and I was supposed to know that? I don't use screen to do this on my system. I just know it allows for a similar effect done right.
–
xenoterracide♦Aug 16 '10 at 19:39

I think I know what you're describing, but it's not a screen feature, it's just a side effect of the way shells work. If you open two shells, the commands typed in one won't show up in the history of the other unless the shell specifically supports it (for example, ZSH does, but you need to explicitly enable it). It doesn't keep separate histories, they both write to the main history file, you just can't see the changes from each shell because typically shells don't check for history file changes once they've loaded
–
Michael Mrozek♦Aug 16 '10 at 20:49