{"id":1161,"date":"2013-11-01T03:53:43","date_gmt":"2013-11-01T09:53:43","guid":{"rendered":"http:\/\/blog.supportpro.com\/?p=1161"},"modified":"2018-10-04T00:32:57","modified_gmt":"2018-10-04T06:32:57","slug":"display-date-and-time-for-commands-executed-in-linux","status":"publish","type":"post","link":"https:\/\/www.supportpro.com\/blog\/display-date-and-time-for-commands-executed-in-linux\/","title":{"rendered":"Display date and time for commands executed in linux"},"content":{"rendered":"<p>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.<\/p>\n<p>History command sample output before setting this variable is as below:<\/p>\n<p>466\u00a0 df -h<br \/>\n467\u00a0 df<br \/>\n468\u00a0 exit<br \/>\n469\u00a0 nfsstat<br \/>\n470\u00a0 find \/ -iname *.ppt<\/p>\n<p>Inorder to display date and time of execution along with the commands, use inbuilt variable HISTTIMEFORMAT to set the values as shown below:<\/p>\n<blockquote><p>#export HISTTIMEFORMAT=&#8217;%F %T &#8216;<\/p><\/blockquote>\n<p>where,<\/p>\n<p>%F for setting year\/month\/day<\/p>\n<p>%T for setting time<\/p>\n<p>Now, if we use the history command we can see the difference. The output will be:<\/p>\n<p>500\u00a0 2011-03-16 17:06:09 exit<br \/>\n501\u00a0 2011-03-16 17:06:14 apt-get install tree<br \/>\n502\u00a0 2011-03-16 17:06:36 tree<br \/>\n503\u00a0 2011-03-16 17:06:54 man tree<br \/>\n504\u00a0 2011-03-16 17:07:02 tree -d<br \/>\n505\u00a0 2011-03-16 17:07:07 tree<\/p>\n<p>This is a temporary setting as once we restart or log out from the machine, the setting will revert back.<\/p>\n<p>Inorder to make the change permanent, just append this variable to .bash_profile for every user:<\/p>\n<blockquote><p>#echo &#8220;export HISTTIMEFORMAT=&#8217;%F %T &#8216;&#8221; &gt;&gt; ~\/.bash_profile<\/p><\/blockquote>\n<p>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:<\/p>\n<blockquote><p>#echo &#8220;export HISTTIMEFORMAT=&#8217;%F %T &#8216;&#8221; &gt;&gt; \/etc\/profile<\/p><\/blockquote>\n<p>If you require help, <a href=\"https:\/\/www.supportpro.com\/requestquote.php\">contact SupportPRO Server Admin<\/a><\/p>\n<p style=\"text-align: center;\"><!--HubSpot Call-to-Action Code --><span id=\"hs-cta-wrapper-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-wrapper\"><span id=\"hs-cta-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-node hs-cta-9d590242-d641-4383-94b4-8cfd62f0af6b\"><!-- [if lte IE 8]><\/p>\n\n\n\n\n\n<div id=\"hs-cta-ie-element\"><\/div>\n\n\n<![endif]--><a href=\"https:\/\/cta-redirect.hubspot.com\/cta\/redirect\/2725694\/9d590242-d641-4383-94b4-8cfd62f0af6b\"><img decoding=\"async\" id=\"hs-cta-img-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-img\" style=\"border-width: 0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/2725694\/9d590242-d641-4383-94b4-8cfd62f0af6b.png\" alt=\"Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value\" \/><\/a><\/span><script charset=\"utf-8\" src=\"https:\/\/js.hscta.net\/cta\/current.js\"><\/script><script type=\"text\/javascript\"> hbspt.cta.load(2725694, '9d590242-d641-4383-94b4-8cfd62f0af6b', {}); <\/script><\/span><!-- end HubSpot Call-to-Action Code --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-1161","post","type-post","status-publish","format-standard","hentry","category-linux-basics"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/comments?post=1161"}],"version-history":[{"count":2,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1161\/revisions"}],"predecessor-version":[{"id":3135,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1161\/revisions\/3135"}],"wp:attachment":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media?parent=1161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/categories?post=1161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/tags?post=1161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}