Bash history format

January 16th, 2010 by Leandro Morgado

Sometimes I need to find out when a certain command was executed in the bash shell. By default, the bash shell will give you this:

shell> history | tail -n 2
 1004  history
 1005  history | tail -n 2

This won’t tell you the date but rather just the order that they were run in. If you want to temporarily see the date, then you need to set this:

shell> export HISTTIMEFORMAT='%F %T '
shell> history | tail -n 2
 1006  2010-01-16 00:55:47  export HISTTIMEFORMAT='%F %T '
 1007  2010-01-16 00:55:49 history | tail -n 2

This will last as long as your environment variable is set, so if you log out you will need to set it again. The %F and %T are standard strftime strings. Check the man page for the full range of options. If you want to make this setting permanent system wide, they add it to your /etc/profile .

Leave a Reply

You must be logged in to post a comment.