cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 9,009 Views

History of commands executed

Jump to solution

When a user executes commands, the "history" of these commands will be recorded in the .bash_history file, in the login directory of the user.  However, these commands are NOT recorded in the .bash_history file as they are executed.  The commands will only appear in the .bash_history file after the user logs out.  However, although the commands do not get recorded in the .bash_history file as each command is executed, they are definitely recorded somewhere.  This is evident by the execution of the history command.  The history command will list the commands that a user has executed, however, those same commands that are output from this command do NOT appear in the .bash_history file - until the user logs out from the shell.  Again, where are the commands being stored/cached when the user executes each one?

Trevor "Red Hat Evangelist" Chandler
Labels (1)
Tags (1)
1 Solution

Accepted Solutions
bonnevil
Starfighter Starfighter
Starfighter
  • 9,007 Views

I believe the history is kept in memory for that shell process.  Remember that each prompt has its own idea of what the history is; if you have two terminals open each running a bash shell, typing a command in one doesn't automatically put it into history in the other (which I think is a good thing!).  This is probably one reason why the HISTSIZE environment variable is set to 1000, to limit memory consumption, but that's just a guess.

The histappend option that's set by default in the BASHOPTS shell variable causes the shell's history to be appended to your current history file when it exits. I think you can do this interactively without exiting the shell with history -a.  I think you can load new lines added to the history file since the shell's session started with history -n.  I really don't use either of these things, though.  The bash(1) and history(1) [aka bash_builtins(1)] man pages have some discussion.

View solution in original post

1 Reply
bonnevil
Starfighter Starfighter
Starfighter
  • 9,008 Views

I believe the history is kept in memory for that shell process.  Remember that each prompt has its own idea of what the history is; if you have two terminals open each running a bash shell, typing a command in one doesn't automatically put it into history in the other (which I think is a good thing!).  This is probably one reason why the HISTSIZE environment variable is set to 1000, to limit memory consumption, but that's just a guess.

The histappend option that's set by default in the BASHOPTS shell variable causes the shell's history to be appended to your current history file when it exits. I think you can do this interactively without exiting the shell with history -a.  I think you can load new lines added to the history file since the shell's session started with history -n.  I really don't use either of these things, though.  The bash(1) and history(1) [aka bash_builtins(1)] man pages have some discussion.

Join the discussion
You must log in to join this conversation.