Bash History: Display Date & Time For Commands

By Vivek Gite @ cyberciti.biz

How do I display shell command history with date and time under UNIX or Linux operating systems?

If the HISTTIMEFORMAT is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment character. Defining the environment variable as follows:

$ HISTTIMEFORMAT="%d/%m/%y %T "

OR

$ echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile

Where,
%d – Day
%m – Month
%y – Year
%T – Time
To see history type

$ history

Sample outputs:

….
..
986 11/03/10 04:31:36 memcached-tool 10.10.28.22:11211 stats
987 11/03/10 04:31:36 w
988 11/03/10 04:31:37 iostat
989 11/03/10 04:31:37 top
990 11/03/10 04:31:37 at
991 11/03/10 04:31:38 atop
992 11/03/10 04:31:40 collectl
993 11/03/10 04:31:41 grep CPU /proc/cpuinfo
994 11/03/10 04:31:45 vmstat 3 100
995 11/03/10 04:31:55 sar -W -f /var/log/sa/sa12
….
..

Nice…

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.