History file, binary?

63 views
Skip to first unread message

Nicholas Papadonis

unread,
Mar 20, 2020, 10:41:58 PM3/20/20
to Korn Shell
I changed my init files to place ksh history on a per process basis into a subdirectory with each history labeled by PID.  It appears that ksh history files are in binary format, while bash is in ASCII text.  My goal was to search histories with grep.

How can I read the old files?  I read something about the "fc -l" command however could not find documentation.

Any guidance appreciated.


Andras Farkas

unread,
Mar 20, 2020, 11:37:37 PM3/20/20
to Nicholas Papadonis, Korn Shell
Which version?
Please try both:
ksh93 --version
(substitute ksh93 with whatever name you normally call the shell by)
and
echo ${.sh.version}
and paste the results here.
> --
> You received this message because you are subscribed to the Google Groups "Korn Shell" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to korn-shell+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/korn-shell/CAKD0t1%2Bpp17TA%3DPgLsmR_JjAHpU5OpgxVTk0wmU_eLZK0MPMGg%40mail.gmail.com.

Andras Farkas

unread,
Mar 21, 2020, 12:19:06 AM3/21/20
to Nicholas Papadonis, Korn Shell
Also, fc is an alias for hist, and hist is documented in the man page
and also by:
hist --help
It's not entirely ideal, since it has leading whitespace, but you can do:
hist -ln -N 1000 | grep yourregex
to search through the past 1001 lines.
or
hist -ln 30 800 | grep yourregex
to search through lines 30 and 800 inclusive.

I don't think there's a way (or remember if there's a way) to get a
plaintext history file. I hope someone else chimes in!

Andras Farkas

unread,
Mar 21, 2020, 12:23:27 AM3/21/20
to Nicholas Papadonis, Korn Shell
Also, looking online, looks like people have much success with:
strings -n 1 .sh_history | grep yourregex

Nicholas Papadonis

unread,
Mar 21, 2020, 12:41:14 AM3/21/20
to Andras Farkas, Korn Shell
1 [debian:~]$ echo $0
-ksh93
2 [debian:~]$ ksh93 --version
  version         sh (AT&T Research) 93u+ 2012-08-01
3 [debian:~]$ echo ${.sh.version}
Version AJM 93u+ 2012-08-01

On Fri, Mar 20, 2020 at 11:37 PM Andras Farkas <deepblu...@gmail.com> wrote:

Andras Farkas

unread,
Mar 21, 2020, 2:24:57 AM3/21/20
to Nicholas Papadonis, Korn Shell
Yep! All my advice will work in your version of ksh. :D
Reply all
Reply to author
Forward
0 new messages