Quote:
Originally Posted by
richmeeker
When I type fc -l (lowever case L), it displays the command history? Where is it pulling the commands from. I thought is was the .sh_history file (since my HISTFILE isn't set, but it appears the .sh_history file contains older information from my previous login. Also, the .sh_history file continas printf statements from login scripts. So how does fc -l really work. Where are the commands being buffered? One more thing. Is it possible to keep the buffer in tact if I log out and back in. Sometime I like to type <ESC>/ to FIND a command I entered yesterday today?
Thanks!
Well, it depends somewhat on what shell you're using and which specific UNIX OS. There's a built-in fc command to the Korn shell, and some (most?) flavors of UNIX have a fc program. I've never noticed a difference, but then again, I don't use it very much (if ever).
Anyway ... the way the versions I know work is that if the HISTFILE environment variable isn't set, it will use the .sh_history file in the user's home directory. If it can't do that it will use a temporary file.
Now while there are numbers associated with the commands, you can't always assume that the larger numbers are associated with newer commands than the smaller numbers are. Once fc reaches a certain limit it will wrap the numbers back around to 1. It keeps track of this, so it knows that (assuming it wrapped at 10000 say...100 commands ago) command 9997 is newer than command 9990 while command 97 is newer than both.
The AIX version of fc defaults to keeping 128 commands in the history if the HISTSIZE environment variable isn't set. I don't know about you, but I can burn through 128 commands in no time at all, so if you want to be keeping commands from the previous day around I'd set HISTSIZE to something bigger than that. There's a limit around 32 or 33 thousand I think, but when you get that big you might see some performance impact.
Even if you have HISTSIZE set large enough, there's a lot that might affect whether your commands from a previous session are still around. Stuff like login scripts, where you log in from, what kind of terminal (or pseudo-terminal, or x-window, or... you get the idea) can all have an impact on that. My suggestion? It's very nice to have, but if you want to be sure of remembering a command later don't rely on the command history. Keep your own log, or alias it in your .env (or .profile or .alias or whatever is appropriate for your OS & shell). Hope this has the info you need.