Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Display date and time for commands executed in linux  (Read 3084 times)

0 Members and 1 Guest are viewing this topic.

Haripriya H

  • Guest
Display date and time for commands executed in linux
« on: May 26, 2014, 08:56:21 am »
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