Tuesday, January 22, 2013

History command With Date and Time In Linux.



Add the line at end of file.

[root@neonserv ~]# vi  /etc/bashrc

# vim:ts=4:sw=4
##
test -s /etc/bash.bashrc.local && . /etc/bash.bashrc.local


Create one file name  "/etc/bash.bashrc.local"  and edit like as follows.

[root@neonserv ~]# vi /etc/bash.bashrc.local

#local bashrc mods
#
# turn on date time stamps in history
#
export HISTTIMEFORMAT="%h/%d - %H:%M:%S "
export HISTCONTROL=ignoreboth
export HISTSIZE=2000

---------------------------
So when you will fire command output will be like this:
[root@neonserv ~]# history
 1033  Jan/22 - 15:30:44 accton
 1034  Jan/22 - 15:31:16 /etc/init.d/psacct start
 1040  Jan/22 - 15:32:06 lastcomm shrii
 1041  Jan/22 - 15:32:10 lastcomm root
 1042  Jan/22 - 15:32:38 lastcomm
 1043  Jan/22 - 15:32:48 lastcomm rm
 1044  Jan/22 - 15:32:51 lastcomm ls
 1045  Jan/22 - 15:32:53 lastcomm root
 1050  Jan/22 - 21:49:44 history
--------------------------