11

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?

  • 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 Aug 22 '13 at 17:32
  • 2
    @tink I don't agree it is that obvious... – Bernhard Aug 23 '13 at 5:28
16

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.