{"id":53,"date":"2024-08-21T14:51:38","date_gmt":"2024-08-21T19:51:38","guid":{"rendered":"https:\/\/www.bluestonesolutionsgroup.com\/?p=53"},"modified":"2024-08-26T15:03:21","modified_gmt":"2024-08-26T20:03:21","slug":"including-date-time-in-the-linux-prompt","status":"publish","type":"post","link":"https:\/\/www.bluestonesolutionsgroup.com\/?p=53","title":{"rendered":"Including Date\/Time in the Linux Prompt"},"content":{"rendered":"\n<p>The basic way to set a prompt is by setting the &#8220;PS1&#8221; variable.<br><br>In Linux (the BASH shell, in particular), the default format is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export PS1=\"&#91;\\u@\\h \\W]\\$ \"<\/code><\/pre>\n\n\n\n<p>That will give you a prompt that looks like this (where &#8220;dir&#8221; is  your current directory)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;username@host dir]$<\/code><\/pre>\n\n\n\n<p>We can add a date\/timestamp to it by changing the prompt to this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export PS1=\"\\D{%F %T} &#91;\\u@\\h \\W]\\$ \"<\/code><\/pre>\n\n\n\n<p>So, for today (August 21, 2024 at 14:45:00), the prompt would look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>2024-08-21 14:45:00 &#91;user@host ~]$<\/code><\/pre>\n\n\n\n<p><strong>So, why would I want to set my prompt this way?<\/strong><\/p>\n\n\n\n<p>Generally, I wouldn&#8217;t.  I tend to like things pretty clean.<\/p>\n\n\n\n<p>But, if I&#8217;m doing a big upgrade with a lot of steps, it would be nice.  Combine that with a terminal emulator that logs everything and you have a pretty decent way to capture &#8220;start\/stop&#8221; times for individual commands.<\/p>\n\n\n\n<p>You could even put some sort of token at the front to make the lines easier to grep out of the log.  This one would put &#8220;[CMD] &#8221; at the front of each line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export PS1=\"&#91;CMD] \\D{%F %T} &#91;\\u@\\h \\W]\\$ \"<\/code><\/pre>\n\n\n\n<p>Keep in mind though.  This prompt is not &#8220;dynamic&#8221;.  It will only show the time at the instant that the prompt is printed.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The basic way to set a prompt is by setting the &#8220;PS1&#8221; variable. In Linux (the BASH shell, in particular), the default format is: That will give you a prompt that looks like this (where &#8220;dir&#8221; is your current directory) &hellip; <a href=\"https:\/\/www.bluestonesolutionsgroup.com\/?p=53\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,18],"tags":[24,26],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-linux","category-unix","tag-linux","tag-unix"],"_links":{"self":[{"href":"https:\/\/www.bluestonesolutionsgroup.com\/index.php?rest_route=\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bluestonesolutionsgroup.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bluestonesolutionsgroup.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bluestonesolutionsgroup.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bluestonesolutionsgroup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=53"}],"version-history":[{"count":1,"href":"https:\/\/www.bluestonesolutionsgroup.com\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":54,"href":"https:\/\/www.bluestonesolutionsgroup.com\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions\/54"}],"wp:attachment":[{"href":"https:\/\/www.bluestonesolutionsgroup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bluestonesolutionsgroup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bluestonesolutionsgroup.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}