Showing posts with label history. Show all posts
Showing posts with label history. Show all posts

Friday, November 4, 2016

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
root@linuxforfreshers.com:~$ vim .bash_profile

$ HISTTIMEFORMAT="%d/%m/%y %T "
:wq
Or
root@linuxforfreshers.com:~$  echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
root@linuxforfreshers.com:~$ source .bash_profile
Where,
%d – Day
%m – Month
%y – Year
%T – Time
root@linuxforfreshers.com:~$  history
Sample outputs:

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

References:
For more info type the following commands:
man bash
help history
man 3 strftime