21

After exporting HISTTIMEFORMAT='%F %T' I tried to query history

But the result shows all the commands are executed on same day.

How can I check the actual date and time of actual command execution?

2
  • That's like asking why you don't have last weeks episode of The Big Bang theory on the VCR you bought this morning...
    – tink
    Commented Aug 22, 2013 at 17:32
  • 7
    @tink I don't agree it is that obvious...
    – Bernhard
    Commented Aug 23, 2013 at 5:28

2 Answers 2

24

If you set the HISTTIMEFORMAT in bash your new entries get stored in the history file with a timestamp, older commands that don't have a timestamp (those before you ever set HISTTIMEFORMAT will display one and the same date-time-stamp (I assume the one from the first entry found with a real timestamp).

This problem should solve itself after your complete history has been updated in a few days.

You can look in ~/.bash_history to see what is the first line that has a date-time-stamp. Those are lines starting with a # followed by a (currently) 10 digit number.

3

I think this is a feature. As you just changed this setting, you can see from ~/.bash_history that the old command do not have a time-stamp stored. So for these commands, it will just assume the current time.

Try to put the export command in ~/.bashrc and execute a few command. You will see, that in ~/.bash_history an additional time-stamp will be save, which can then be displayed by history. So for new commands it should work as expected.

Thus: Not backwards compatible with commands executed in a different terminal window in the past.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .