[Ilugc] linux command history question?

  • From: knutties@xxxxxxxxx (Natarajan K)
  • Date: Thu Aug 18 23:00:46 2005

On 8/18/05, Sai Kiran <saikiranrgda@xxxxxxxxx> wrote:

i was wondering where bash shell stores all the command history in its memory.
Yup, it does. The HISTORY section of the bash man page is quite infromative.

i the reason for finding this id because i want to access the history
of commands that were used in another session or terminal.
Basic searches did not yield positive results for me. This document
(cnswww.cns.cwru.edu/~chet/bash/rose94.pdf) has a section which says
<quote>
Finally, the ksh history implementation differs slightly from bash.
Each instance of bash keeps the history list in memory and offers
options to the history builtin to write the list to or read it from a
named file. Ksh keeps the history in a file, which it accesses each
time a command is saved to or retrieved from the history. Ksh history
files may be shared among different concurrent instances of ksh, which
could be a benefit to the user.
</quote>

You could use the history builtin command and the PROMPT_COMMAND
environment variable to achieve this purpose.

Setting you PROMPT_COMMAND to "history -w; history -r" will make sure
that you history is saved and restored after command is executed. You
would also need to make sure you start off with an absolutely spotless
history :-) Otherwise you will history commands alternatively
overwriting your $HISTFILE.

HTH,
Natarajan
-- 
http://puggy.symonds.net/~natarajan

Other related posts: