Home Linux Basics Display date and time for commands executed in linux

Display date and time for commands executed in linux

by Bella

We can always set time to the commands showed in history command as it will be totally a security measure and can be used for troubleshooting/fingerprinting a security threat.

History command sample output before setting this variable is as below:

466  df -h
467  df
468  exit
469  nfsstat
470  find / -iname *.ppt

Inorder to display date and time of execution along with the commands, use inbuilt variable HISTTIMEFORMAT to set the values as shown below:

#export HISTTIMEFORMAT=’%F %T ‘

where,

%F for setting year/month/day

%T for setting time

Now, if we use the history command we can see the difference. The output will be:

500  2011-03-16 17:06:09 exit
501  2011-03-16 17:06:14 apt-get install tree
502  2011-03-16 17:06:36 tree
503  2011-03-16 17:06:54 man tree
504  2011-03-16 17:07:02 tree -d
505  2011-03-16 17:07:07 tree

This is a temporary setting as once we restart or log out from the machine, the setting will revert back.

Inorder to make the change permanent, just append this variable to .bash_profile for every user:

#echo “export HISTTIMEFORMAT=’%F %T ‘” >> ~/.bash_profile

And to set this value to the new user which are going to be created on the machine, export the setting to /etc/profile file:

#echo “export HISTTIMEFORMAT=’%F %T ‘” >> /etc/profile

If you require help, contact SupportPRO Server Admin

Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value

Leave a Comment