{"id":13221,"date":"2019-04-01T08:18:56","date_gmt":"2019-04-01T08:18:56","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13221"},"modified":"2019-04-01T08:18:56","modified_gmt":"2019-04-01T08:18:56","slug":"set-date-and-time-for-each-command-you-execute-in-bash-history","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/set-date-and-time-for-each-command-you-execute-in-bash-history\/","title":{"rendered":"Set Date and Time for Each Command You Execute in Bash History"},"content":{"rendered":"<p>By default, all commands executed by\u00a0<strong>Bash<\/strong>\u00a0on the command line are stored in history buffer or recorded in a file called\u00a0<strong>~\/.bash_history<\/strong>. This means that a system administrator can view a list of commands executed by users on the system or a user can view his\/her command history using the\u00a0<a href=\"https:\/\/www.tecmint.com\/history-command-examples\/\" target=\"_blank\" rel=\"noopener\">history command<\/a>\u00a0like so.<\/p>\n<pre>$ history\r\n<\/pre>\n<div id=\"attachment_24189\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Linux-History-Command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24189\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Linux-History-Command.png\" alt=\"Linux History Command\" width=\"567\" height=\"420\" aria-describedby=\"caption-attachment-24189\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-24189\" class=\"wp-caption-text\">Linux History Command<\/p>\n<\/div>\n<p>From the output of the\u00a0<a href=\"https:\/\/www.tecmint.com\/history-command-examples\/\" target=\"_blank\" rel=\"noopener\">history command<\/a>\u00a0above, the\u00a0<strong>date<\/strong>\u00a0and\u00a0<strong>time<\/strong>\u00a0when a command was executed is not shown. This is the default setting on most if not all Linux distributions.<\/p>\n<p>In this article, we will explain how you can configure time stamp information when each command in the Bash history was executed to be displayed.<\/p>\n<p>The\u00a0<strong>date<\/strong>\u00a0and\u00a0<strong>time<\/strong>\u00a0associated with each history entry can be written to the history file, marked with the history comment character by setting the\u00a0<strong>HISTTIMEFORMAT<\/strong>\u00a0variable.<\/p>\n<p>There are two possible ways of doing this: one does it temporarily while the other makes it permanent.<\/p>\n<p>To set\u00a0<strong>HISTTIMEFORMAT<\/strong>\u00a0variable temporarily, export it as below on the command line:<\/p>\n<pre>$ export HISTTIMEFORMAT='%F %T'\r\n<\/pre>\n<p>In the export command above, the time stamp format:<\/p>\n<ol>\n<li><code>%F<\/code>\u00a0\u2013 expands to full date same, as\u00a0<strong>%Y-%m-%d<\/strong>\u00a0(year-month-date).<\/li>\n<li><code>%T<\/code>\u00a0\u2013 expands to time; same as\u00a0<strong>%H:%M:%S<\/strong>\u00a0(hour:minute:seconds).<\/li>\n<\/ol>\n<p>Read through the\u00a0<a href=\"https:\/\/www.tecmint.com\/sort-ls-output-by-last-modified-date-and-time\/\" target=\"_blank\" rel=\"noopener\">date command<\/a>\u00a0man page for additional usage information:<\/p>\n<pre>$ man date\r\n<\/pre>\n<p>Then check your command history as follows:<\/p>\n<pre>$ history \r\n<\/pre>\n<div id=\"attachment_24190\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Set-Date-and-Time-on-Linux-Commands-History.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24190\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Set-Date-and-Time-on-Linux-Commands-History.png\" alt=\"Display Linux Command History with Date and Time\" width=\"564\" height=\"401\" aria-describedby=\"caption-attachment-24190\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-24190\" class=\"wp-caption-text\">Display Linux Command History with Date and Time<\/p>\n<\/div>\n<p>However, if you want to configure this variable permanently, open the file\u00a0<code>~\/.bashrc<\/code>\u00a0with your favorite editor:<\/p>\n<pre>$ vi ~\/.bashrc\r\n<\/pre>\n<p>And add the line below in it (you mark it with a comment as your own configuration):<\/p>\n<pre>#my config\r\nexport HISTTIMEFORMAT='%F %T'\r\n<\/pre>\n<p>Save the file and exit, afterwards, run the command below to effect the changes made to the file:<\/p>\n<pre>$ source ~\/.bashrc\r\n<\/pre>\n<p>That\u2019s all! Do share with us any interesting history command tips and tricks or your thoughts about this guide via the comment section below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/display-linux-command-history-with-date-and-time\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By default, all commands executed by\u00a0Bash\u00a0on the command line are stored in history buffer or recorded in a file called\u00a0~\/.bash_history. This means that a system administrator can view a list of commands executed by users on the system or a user can view his\/her command history using the\u00a0history command\u00a0like so. $ history Linux History Command &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/set-date-and-time-for-each-command-you-execute-in-bash-history\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Set Date and Time for Each Command You Execute in Bash History&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13221","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13221"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13221\/revisions"}],"predecessor-version":[{"id":13222,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13221\/revisions\/13222"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}