Monday, December 13, 2010

Display Timestamp for history command in bash shell


In Linux, We all must be using history command to list down commands which we have used in past and reuse it to save time.

Typically when you type " history " command on terminal, it will give you just a list of commands as shown below.
-----------------------------------------------------
[root@localhost ~]# history
  980  fdisk -l
  981  poweroff
  982  /etc/init.d/smb status
  983  ls
-------------------------------------------------------
If HISTTIMEFORMAT variable is set , history command will display Date and Time stamps information for all commands.

[root@localhost ~]# export HISTTIMEFORMAT=' %F %T '
[root@localhost ~]# history
 1012  2010-12-12 15:26:16ifconfig
 1013  2010-12-12 15:26:23cat .bashrc
 1014  2010-12-12 15:26:38cd /root/
 1015  2010-12-12 15:26:38ls
 1016  2010-12-12 15:26:43cd Desktop/
[root@localhost Desktop]#
---------------------------------------------------------------
This can be useful in audit purpose . You can add above mentioned command to your .bashrc  file to start storing date and time information as soon as user opens terminal.

--
Sumit

No comments:

Post a Comment