Home / Uncategorized / Bash Trick – Display Timestamp For Each Command In History

Bash Trick – Display Timestamp For Each Command In History

Ever go through your history, and wish you knew the exact date and time a given command was typed? Well theres actually a fairly simple trick. It’s the global HISTTIMEFORMAT variable.

To test it out, copy and paste the following into your bash prompt, type a few commands, then type history again.
$ HISTTIMEFORMAT="%d/%m/%y %T "

You should see the typical history output, with the date and time prepended to each line. Heres an example from my history output.
497 24/04/14 01:16:46 man nmap
498 24/04/14 01:16:46 sudo su -
499 24/04/14 01:16:46 sudo su -
500 24/04/14 01:16:46 exit
501 24/04/14 01:16:53 clear
502 24/04/14 01:16:54 HISTTIMEFORMAT="%d/%m/%y %T "
503 24/04/14 01:16:57 ls
504 24/04/14 01:17:04 whoami
505 24/04/14 01:17:17 ps aux |grep bla
506 24/04/14 01:17:20 history |tail

Now if you want this to be permanent, then execute the following, to add it to your .bash_profile
$ echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile

About J

Welcome to my little corner of the InterWebs! Most of what I post on LinuxDigest is about either automation, something I find interesting, or something I just learned myself. If you want me to post an article about something, just let me know! Im more than happy to help and teach others Linux.

Leave a Reply

Your email address will not be published. Required fields are marked *

*