Why does my history command show wrong execution date?

OS version : Fedora 33

history command, by default, doesn’t show the date of execution.
From googling, I figured that if you set the global env variable HISTTIMEFORMAT, one can view the execution dates as well.

But, when I set it, I see the execution date of almost commands wrongly displayed as today.

Below is a snipped output of history command after setting HISTTIMEFORMAT variable.
All commands till line 998 are not executed today (05-April-2021), but it is wrongly displayed with today’s date.

Any idea what I am doing wrong ?

988 05 Apr 2021 chmod -vv 700 gg.zip
989 05 Apr 2021 ls -l
990 05 Apr 2021 pwd
991 05 Apr 2021 ls -al
992 05 Apr 2021 clear
993 05 Apr 2021 cd /tmp
994 05 Apr 2021 man dnf > dnfmanPage.txt
995 05 Apr 2021 less dnfmanPage.txt
996 05 Apr 2021 vi dnfmanPage.txt
997 05 Apr 2021 sudo dnf upgrade
998 05 Apr 2021 cal
999 05 Apr 2021 history
1000 05 Apr 2021 export HISTTIMEFORMAT='%d %b %Y ’
1001 05 Apr 2021 history

Since Bash didn’t record their execution date anywhere until you set HISTTIMEFORMAT, all previous commands are recorded as if they are executed when you set HISTTIMEFORMAT; it is expected behavior. But from now on you will get correct timestamps.


Thank You ersen.
Are you suggesting to add export HISTTIMEFORMAT='%d %b %Y ' to my ~/.bashrc file so that bash will always record the timestamp of each command execution ?

Yes, you can see strftime man page for different format options like hour, minute, etc.

1 Like