Operating System - HP-UX
1832487 Members
4429 Online
110043 Solutions
New Discussion

retrieving history using <ESC> K

 
SOLVED
Go to solution
Rich1970
New Member

retrieving history using <ESC> K

I am accumulating commands entered in the ~/.sh_history file. I ran the command "set -o vi" to allow vi commands from command line. I thought using commands such as k would walk back through the .sh_history file. It appears to walk it back to a certain point and stops. So it appears, K is walking a different buffer somewhere? Does anyone know ehre? Ideally, I would like to recall commands using the find command "/foo" to find the last entered command foo.

Also, is there away to only log commands phyisically typed in from the keyboard to the .sh_history file. Apparently, large ksh scripts that I run log immense data which I don't care about. Thanks.

11 REPLIES 11
Ninad_1
Honored Contributor

Re: retrieving history using <ESC> K

You can use the HISTSIZE variable.
e.g. export HISTSIZE=100
to store last 100 commands
.sh_history infact logs only commands and not the output, so not to worry.

Regards,
Ninad
Rich1970
New Member

Re: retrieving history using <ESC> K

OK! If HISTSIZE is set, I can see that K is retrieving the commands buffered. However, when I log out and back on, the command retrieve history is not working with K even though the .sh_history file still exists. So it appears K is retrieving commands from another buffer, does anyone know where?

Thanks!
Ninad_1
Honored Contributor

Re: retrieving history using <ESC> K

Do you have HISTFILE variable set ?
Please do echo $HISTFILE

If HISTFILE is not defined to any specific file, then default is .sh_history

Regards,
Ninad
Rich1970
New Member

Re: retrieving history using <ESC> K

no it is not set. I figured out the fc -l command lists the recent commands, but it doesn't appear to get the command from the .sh_history because there are many other commands in the file that do not show up when I type fc -l.

What file are the commands buffered to because it doesn't appear that the fc -l command or the ESC K command walks .sh_history.
Dennis Handly
Acclaimed Contributor

Re: retrieving history using <ESC> K

Are you exporting HISTFILE too? Are you root?

I have no problems with using /foo with N different shells on different computers.

>large ksh scripts that I run log immense data which I don't care about.

You might want to use the following so you don't log functions:
set -o nolog # don't save functions in history file
Rich1970
New Member

Re: retrieving history using <ESC> K

Thank you very much Dennis. Adding the set -o nolog seems to have done the trick. my / command now works when searching strings in the search history.

much appreicated.
Dennis Handly
Acclaimed Contributor
Solution

Re: retrieving history using <ESC> K

>my / command now works when searching strings in the search history.

You could have also solved it by using HISTSIZE=10000 or so. I typically use 1000 but also grep .sh_history for valuable but "expired" commands.

I found nolog because I read every stinkin' word on the man page and I kept seeing my pushd/popd functions logged in HISTFILE.

You haven't assigned any points yet, please read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33
Ninad_1
Honored Contributor

Re: retrieving history using <ESC> K

The .sh_history file you are refering to - is it in the home directory of the user or somewhere else ?
If HISFILE is not set then history is stored in $HOME/.sh_history
If the .sh_history file you are checking is in fact in $HOME, then try one thing -
mv .sh_history .sh_history.org
and then try fc -l

Regards,
Ninad
Rich1970
New Member

Re: retrieving history using <ESC> K

Dennis - I do have me HISTSIZE set to 3000 but the retrieve didn't seem to work until I did the set -o nolog option. Actually, I noticed /foo isn't going back through the entire file to locate foo. For example, I currently have 232 lines in my .sh_history file. I can hit k which will walk me back through the last 155 commands. Not sure why it is not walking the entire 232 since my HISTSIZE is set to 3000. I am hoping to be able to walk the entire 3000 command buffer. Still not sure why it doesn't work, but it is working better because the .sh_history file is cleaner due to the nolog option

BTW - I am not root



Ninad,

Thanks for your posts.

HISTFILE is not set so it is defaulting to ~/.sh_history. I did your test and here are my results of the fc.

meekerr@stp03: /home/vtl/meekerr
==> ls -a .sh_history
.sh_history
meekerr@stp03: /home/vtl/meekerr
==> fc -l
197 asdf asdf asdf
198 asdf
199 asdf
200 hg
201 asdf
202 asdf aasd
203 ia2b
204 man fc
205 fc First
206 man fc
207 cd
208 fc -l
209 ls -a .sh_history
210 clear
211 ls -a .sh_history
212 fc -l
meekerr@stp03: /home/vtl/meekerr
==> mv .sh_history .sh_history.org
meekerr@stp03: /home/vtl/meekerr
==> fc -l
199 asdf
200 hg
201 asdf
202 asdf aasd
203 ia2b
204 man fc
205 fc First
206 man fc
207 cd
208 fc -l
209 ls -a .sh_history
210 clear
211 ls -a .sh_history
212 fc -l
213 mv .sh_history .sh_history.org
214 fc -l
meekerr@stp03: /home/vtl/meekerr

Hmmm - Is there a separate command buffer for command history or is it using .sh_history?

Peter Nikitka
Honored Contributor

Re: retrieving history using <ESC> K

Hi,

I'm shure the shell keeps its history in memory - or at least a part of it - so it wouldn'z be necessary to open a file for each key stroke.

mfg Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Dennis Handly
Acclaimed Contributor

Re: retrieving history using <ESC> K

>I do have my HISTSIZE set to 3000 but the retrieve didn't seem to work until I did the set -o nolog option.

You didn't have 3000 lines of functions did you? ;-)

I have 1000 and I can do "history -999". And then grep 9000+ lines.

>Not sure why it is not walking the entire 232 since my HISTSIZE is set to 3000.

I did history to pick a line close to 1000 back and / found a unique string there.

>Is there a separate command buffer for command history or is it using .sh_history?

I suppose there is an in memory copy? If you have HISTFILE set wrong or root with sh, it doesn't put it to a file.

>Peter: I'm sure the shell keeps its history in memory - or at least a part of it - so it wouldn't be necessary to open a file for each key stroke.

It probably buffers lines? I'm able to see recent commands from other shells.