Knowledgebase


Portal Home > Knowledgebase > Hosting FAQ's > How to add timestamp to history command?

How to add timestamp to history command?

history command lists all executed command on server.

By default output of command is as follows:

989  date
990  history
991  history
992  w
993  top
994  w
995  cd /tmp
996  ls -la

 

After you add timestamp, it will show you a detailed output with date, time and command.

SSH to server as root and edit file /root/.bash_profile with your favorite editor and add following line:

Export HISTTIMEFORMAT="%F %T "
Now logout and login again and execute history command, you will see
Detailed output as follows:-
root@Server[~]#history
19  04/25/10 08:26:48 hostname
20  04/25/10 08:46:34 history
21  04/25/10 08:46:48 w
22  04/25/10 08:46:50 date
23  04/25/10 08:46:52 cal
24  04/25/10 08:46:53 ls -la
25  04/25/10 08:46:55 top
26  04/25/10 08:47:11 tail -f /var/log/messages
27  04/25/10 08:47:29 history


Also Read