How to find out the Time Stamp of the history?
As I run command 'history' I got a long list of command history with the command number. But how can I find out the Time Stamp, i.e., at what time a command is executed?
|
Hi,
Try setting the HISTTIMEFORMAT environment variable first, as follows: Code:
HISTTIMEFORMAT="%Y-%m-%d %T " Regards, Clifford |
Hi,
Sorry. I thought your answer is correct. But as I look the history deeply I found all the command in the history list have the same Time Stamp. For example, I have many commands yesterday. But as call the history now, I see all the command from yesterday or earlier have the same Time Stamp from today. This is not what I want. |
Hi again,
I saw the same thing earlier this week on a different machine, but then got correct timestamps when I tried it on my own machine this morning. Sorry, I should have mentioned that. I think the variable needs to be set in order for the timestamp data to be collected/saved. That means what you're seeing is entries that weren't saved with a timestamp, and there is no way to see timestamps for such entries. Setting it in your profile (or system wide in /etc/bash.bashrc) should solve the problem going forward. I hope this helps. Regards, Clifford |
Hi again,
You can easily verify whether the timestamps are being saved. They're saved in your ~/.bash_history file with the rest of the info, in the form of comment lines like this: Code:
#1408637756 |
Quote:
This is what happens when you first enable history timestamping. It all gets stamped the hour/minute/second that bash re-reads ~/.bash_history. Successive commands will show a different h:m:s on commands. |
Quote:
Code:
... |
Quote:
|
Quote:
Code:
... Code:
... Why? |
Hi there,
As far as I know, the shell reads the history from the file when it starts, then keeps track of the history in memory, and only saves it to the file again when you exit. This means you will see entries in the output from the history command which is not saved in the file yet. It also means you might not see what you expect in the history if multiple sessions use the same history file (which is the default). There's an explanation and possible solution (which I haven't tried) at http://linuxcommando.blogspot.com/20...-multiple.html. You could also change HISTFILE to unique names if you prefer. This is great if you main goal is to record the history for audit purposes, but usually means you can't pick up your old history from a new session, making it less convenient to use. Regards, Clifford |
Quote:
|
All times are GMT -5. The time now is 10:40 AM. |