Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where is history file?

Status
Not open for further replies.

babeo

Technical User
Mar 30, 2000
398
CA
Hi all<br><br>1) I am looking for the history file that contains the commands entered on Sun Solaris. I can use ESC + k to retrieve it in ksh or run the HISTORY command to see what command I used before, but I am unable to find where the file locates (I already check the .sh_history and even .cshrc, but the commands are different when I run history command ?!)<br><br>2) The file can be created with different name provide it is specified in the .profile , isn't it?<br><br>Thanks for your help
 
Yes, you can put an entry like export HISTFILE={filename} in your .profile or in .cshrc or .kshrc and this will be your new history file. <p>Jon Zimmer<br><a href=mailto:b0rg@pcgeek.net>b0rg@pcgeek.net</a><br><a href= Aetea Information Technology</a><br>The software required `Windows 95 or better', so I installed Linux.<br>
 
babeo,<br><br>It actually *is* in the .sh_history file (or $HISTFILE, as Jon says) but your commands don't get there straight away, the shell seems to write them out when it has a minute to itself.<br><br>I've noticed that, when running ksh in two windows, I can force my current window to pick up what's in the .sh_history file (from the other window) with Ctrl-C, I've not seen that documented anywhere though.<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Thanks Jon and Mike<br><br>However, I still don't get it, here is the &quot;clue&quot;, I enter whole bunch of letters q,r,s,t,u,v and check in order below:<br><br>1) wrdbi1% history<br>&nbsp;&nbsp;&nbsp;167&nbsp;&nbsp;q<br>&nbsp;&nbsp;&nbsp;168&nbsp;&nbsp;r<br>&nbsp;&nbsp;&nbsp;169&nbsp;&nbsp;s<br>&nbsp;&nbsp;&nbsp;170&nbsp;&nbsp;t<br>&nbsp;&nbsp;&nbsp;171&nbsp;&nbsp;u<br>&nbsp;&nbsp;&nbsp;172&nbsp;&nbsp;v<br>&nbsp;&nbsp;&nbsp;173&nbsp;&nbsp;history<br><br>2) wrdbi1% tail .sh_history<br>rm 2003*<br>rm 2103*<br>rm 2203* 2303* 2403*<br>rm 2503* 2603* 2703* 2803* 2903* 3003*<br>ls 0703* 0803* 0903*<br>rm 0703* 0803* 0903*<br>ls -la¦more<br>more .sh_history<br>exit<br><br>I'm sure I don't see my commands stored in .sh_history even the commands I entered a few days ago.&nbsp;&nbsp;And in .profile, I don't see the setup for history file, that's fine, however, there must be a file stores the online commands, but I could not find where is it!<br><br>Thanks if you have any clue
 
is your HISTFILE env var set? type the command 'env' <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Hi Mike<br><br>No, there is not the setup for HISTFILE.&nbsp;&nbsp;However, is it true that the commands are attached in the memmory and until the user logs out and logs in again, then those commands will be updated in the .sh_history?&nbsp;&nbsp;This is due to many persons log in using the same id, which causes it can not update the file?
 
try this in the .profile<br><br>export HISTFILE=~/.sh_history.$$<br><br>that will give each login under that id its own history file - you have to remember to delete them after a while though - or you will get quite a few. (the $$ is the current process id by the way) <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Try this out it works in my case<br><br>$ export HISTFILE=/tmp/ami1234<br>$ ksh -o vi<br>$ lsdsd<br>ksh: lsdsd:&nbsp;&nbsp;not found<br>$ abracadabra<br>ksh: abracadabra:&nbsp;&nbsp;not found<br><br>$ tail -2 /tmp/ami1234<br>lsdsd<br>abracadabra<br><br>The HISTFILE consists of the .kshrc output along with the history.<br><br>Adios <p> amit<br><a href=mailto: crazy_indian@mailcity.com> crazy_indian@mailcity.com</a><br><a href= > </a><br>to bug is human to debug devine
 
If you run more than one login session at a time (I.e., more than one <i>xterm</i> on an X windows workstation) you may want to maintain a seperate history file for each login session. Do it this way:<br>in your <i>.profile</i><br><br><i>export HISTFILE=~/.hist$$<i><br># Something like what Mike put up before :)<br># It doesn't have to be called .hist, it could be any name you want.<br><br>This creates a history file whose name begins with <b>.hist</b> and ends with a number that is essentially guaranteed to be unique.&nbsp;&nbsp;Yes this will create a lot of stray history files , but you can clean these up through a cron job like this:<br><br><i>0 2 * * * rm ~/.hist*</i><br><br>that will remove all history files in ~'s directory everyday at 2 A.M.<br><br>If you wanted to get rid of all of them you could use a <i>find</i> command instead of <i>rm</i>&nbsp;&nbsp;like this:<br><br><i>0 2 * * * find / -name &quot;.hist*&quot; -exec rm {} \;</i> <p>Jon Zimmer<br><a href=mailto:b0rg@pcgeek.net>b0rg@pcgeek.net</a><br><a href= Aetea Information Technology</a><br>The software required `Windows 95 or better', so I installed Linux.<br>
 
Thank you very much every body.&nbsp;&nbsp;It helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top