If I run
history, I can see my latest executed commands.
But if I do
tail -f $HISTFILE or
tail -f ~/.bash_history, they do not get listed.
Does the file get locked, is there a temporary location or something similar?
Bash maintains the list of commands internally in memory while it's running. They are written into
If you want to force the command history to be written out, you can use the
There is also a
which may suit you more depending on exactly how you use your history.
If you want to make sure that they're always written immediately, you can put that command into your
bash keeps it in working memory, bash can be configured to save it when bash closes or after each command, and to be loaded when bash starts or on request.
If you configure to save after each command, then consider the implications of having multiple bash running at same time. (command lines will be interleaved)
(Not an answer but I cannot add comments)
If you are checking
For example, supposing an output like:
and you want purge the
Commands are saved in memory (RAM) while your session is active. As soon as you close the shell, the commands list gets written to bash_history before shutdown.
Thus, you won't see history of current session in bash_history.
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?