Skip to content

Commit 83ff6d2

Browse files
update mini blog post on the date command
1 parent 168c98a commit 83ff6d2

File tree

7 files changed

+11
-10
lines changed

7 files changed

+11
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ I'm addicted to reading fantasy/sci-fi books, so I have a [blog](https://learnby
6262

6363
## Mini blog posts
6464

65-
* [Basic examples for the Linux date command](https://learnbyexample.github.io/mini/mini/linux-date-command-examples/)
65+
* [Basic examples for the Linux date command](https://learnbyexample.github.io/mini/linux-date-command-examples/)
6666
* [CLI text editing with ed](https://learnbyexample.github.io/mini/cli-text-editing-with-ed/)
6767
* [Computing from the Command Line: sales report](https://learnbyexample.github.io/mini/cli-computing-sales/)
6868
* [Bash compound commands and redirection](https://learnbyexample.github.io/mini/bash-compound-commands-redirection/)

atom.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<link href="https://learnbyexample.github.io/atom.xml" rel="self" type="application/atom+xml"/>
66
<link href="https://learnbyexample.github.io"/>
77
<generator uri="https://www.getzola.org/">Zola</generator>
8-
<updated>2025-01-23T00:00:00+00:00</updated>
8+
<updated>2025-01-28T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
1010
<entry xml:lang="en">
1111
<title>Understanding Python re(gex)? book announcement</title>
@@ -484,7 +484,7 @@
484484
<entry xml:lang="en">
485485
<title>Basic examples for the Linux date command</title>
486486
<published>2024-07-31T00:00:00+00:00</published>
487-
<updated>2024-08-13T00:00:00+00:00</updated>
487+
<updated>2025-01-28T00:00:00+00:00</updated>
488488
<link rel="alternate" href="https://learnbyexample.github.io/mini/linux-date-command-examples/" type="text/html"/>
489489
<id>https://learnbyexample.github.io/mini/linux-date-command-examples/</id>
490490
<content type="html">&lt;p&gt;I rarely ever use the &lt;code&gt;date&lt;&#x2F;code&gt; command, but when I need it I almost always struggle to get the right incantation. So, I&#x27;m just going to record such examples in this blog post (and some good to know features).&lt;&#x2F;p&gt;
@@ -497,7 +497,7 @@
497497
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;Wednesday &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;31 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;July &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;2024 03&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;53&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;01 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;PM IST
498498
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
499499
&lt;p&gt;Instead, I need particular parts in a particular format. For example, to represent the time component in a dynamically constructed filename as part of a shell script.&lt;&#x2F;p&gt;
500-
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# same as: date +%F or date -I
500+
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# same as: date +%F or date -I or date --iso-8601
501501
&lt;&#x2F;span&gt;&lt;span&gt;$ date &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;+%&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;Y&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-%&lt;&#x2F;span&gt;&lt;span&gt;m&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-%&lt;&#x2F;span&gt;&lt;span&gt;d
502502
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;2024&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;07&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;31
503503
&lt;&#x2F;span&gt;&lt;span&gt;
@@ -568,6 +568,7 @@
568568
&lt;h2 id=&quot;resource-links&quot;&gt;Resource links&lt;&#x2F;h2&gt;
569569
&lt;ul&gt;
570570
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;coreutils&#x2F;manual&#x2F;coreutils.html#date-invocation&quot;&gt;GNU date command manual&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
571+
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;coreutils&#x2F;manual&#x2F;coreutils.html#Examples-of-date&quot;&gt;&amp;quot;Examples of date&amp;quot; section from the manual&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
571572
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;unix.stackexchange.com&#x2F;questions&#x2F;tagged&#x2F;date?tab=Votes&quot;&gt;Top voted Q&amp;amp;A on unix.stackexchange for the date command tag&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
572573
&lt;&#x2F;ul&gt;
573574
</content>

mini/linux-date-command-examples/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html><html lang=en><head><meta content="IE=edge" http-equiv=X-UA-Compatible><meta content="text/html; charset=utf-8" http-equiv=content-type><meta content="width=device-width,initial-scale=1.0,maximum-scale=1" name=viewport><title>Basic examples for the Linux date command</title><link href=https://learnbyexample.github.io/atom.xml rel=alternate title=RSS type=application/atom+xml><script src=https://cdnjs.cloudflare.com/ajax/libs/slideout/1.0.1/slideout.min.js></script><link href=https://learnbyexample.github.io/site.css rel=stylesheet><meta content="Basic examples for the Linux date command" property=og:title><meta content=website property=og:type><meta content="Examples and resource links for the Linux date command." property=og:description><meta content=https://learnbyexample.github.io/linux-date-command-examples/ property=og:url><meta content=@learn_byexample property=twitter:site><link href=https://learnbyexample.github.io/favicon.svg rel=icon><link rel="shortcut icon" href=https://learnbyexample.github.io/favicon.png><body><div class=container><div class=mobile-navbar id=mobile-navbar><div class=mobile-header-logo><a class=logo href=/>learnbyexample</a></div><div class="mobile-navbar-icon icon-out"><span></span><span></span><span></span></div></div><nav class="mobile-menu slideout-menu slideout-menu-left" id=mobile-menu><ul class=mobile-menu-list><li class=mobile-menu-item><a href=https://learnbyexample.github.io/books> Books </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/mini> Mini </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tips> Tips </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tags> Tags </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/about> About </a></ul></nav><header id=header><div class=logo><a href=https://learnbyexample.github.io>learnbyexample</a></div><nav class=menu><ul><li><a href=https://learnbyexample.github.io/books> Books </a><li><a href=https://learnbyexample.github.io/mini> Mini </a><li><a href=https://learnbyexample.github.io/tips> Tips </a><li><a href=https://learnbyexample.github.io/tags> Tags </a><li><a href=https://learnbyexample.github.io/about> About </a></ul></nav></header><main><div class=content id=mobile-panel><div class=post-toc id=post-toc><h2 class=post-toc-title>Contents</h2><div class="post-toc-content always-active"><nav id=TableOfContents><ul><li><a class=toc-link href=https://learnbyexample.github.io/mini/linux-date-command-examples/#really-basic-examples>Really basic examples</a><li><a class=toc-link href=https://learnbyexample.github.io/mini/linux-date-command-examples/#displaying-and-converting-epoch-seconds>Displaying and converting epoch seconds</a><li><a class=toc-link href=https://learnbyexample.github.io/mini/linux-date-command-examples/#date-arithmetic>Date arithmetic</a><li><a class=toc-link href=https://learnbyexample.github.io/mini/linux-date-command-examples/#resource-links>Resource links</a></ul></nav></div></div><article class=post><header class=post__header><h1 class=post__title><a href=https://learnbyexample.github.io/mini/linux-date-command-examples/>Basic examples for the Linux date command</a></h1><div class=post__meta><span class=post__time>2024-07-31</span></div></header><div class=post-content><p>I rarely ever use the <code>date</code> command, but when I need it I almost always struggle to get the right incantation. So, I'm just going to record such examples in this blog post (and some good to know features).<p>There'll also be learning resources linked at the end of the post.</p><br><h2 id=really-basic-examples>Really basic examples</h2><p>The <code>date</code> command by itself shows the current time. But that's rarely what I need, since I could just use the calendar widget at the bottom of my desktop screen. Perhaps useful to copy the string format and modify system time with the <code>-s</code> option?<pre class=language-ruby data-lang=ruby style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-ruby data-lang=ruby><span style=color:#7f8989;># use the -u option for UTC (Coordinated Universal Time)
22
</span><span>$ date
33
</span><span style=color:#5597d6;>Wednesday </span><span style=color:#b3933a;>31 </span><span style=color:#5597d6;>July </span><span style=color:#b3933a;>2024 03</span><span style=color:#72ab00;>:</span><span style=color:#b3933a;>53</span><span style=color:#72ab00;>:</span><span style=color:#b3933a;>01 </span><span style=color:#5597d6;>PM IST
4-
</span></code></pre><p>Instead, I need particular parts in a particular format. For example, to represent the time component in a dynamically constructed filename as part of a shell script.<pre class=language-ruby data-lang=ruby style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-ruby data-lang=ruby><span style=color:#7f8989;># same as: date +%F or date -I
4+
</span></code></pre><p>Instead, I need particular parts in a particular format. For example, to represent the time component in a dynamically constructed filename as part of a shell script.<pre class=language-ruby data-lang=ruby style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-ruby data-lang=ruby><span style=color:#7f8989;># same as: date +%F or date -I or date --iso-8601
55
</span><span>$ date </span><span style=color:#72ab00;>+%</span><span style=color:#5597d6;>Y</span><span style=color:#72ab00;>-%</span><span>m</span><span style=color:#72ab00;>-%</span><span>d
66
</span><span style=color:#b3933a;>2024</span><span style=color:#72ab00;>-</span><span style=color:#b3933a;>07</span><span style=color:#72ab00;>-</span><span style=color:#b3933a;>31
77
</span><span>
@@ -53,4 +53,4 @@
5353
</span><span>$ prev_date=</span><span style=color:#d07711;>'2024-02-23'
5454
</span><span>$ date </span><span style=color:#72ab00;>-</span><span>d </span><span style=color:#d07711;>"$prev_date"' +7 days' </span><span style=color:#72ab00;>+%</span><span style=color:#5597d6;>F
5555
</span><span style=color:#b3933a;>2024</span><span style=color:#72ab00;>-</span><span style=color:#b3933a;>03</span><span style=color:#72ab00;>-</span><span style=color:#b3933a;>01
56-
</span></code></pre><br><h2 id=resource-links>Resource links</h2><ul><li><a href=https://www.gnu.org/software/coreutils/manual/coreutils.html#date-invocation>GNU date command manual</a><li><a href="https://unix.stackexchange.com/questions/tagged/date?tab=Votes">Top voted Q&A on unix.stackexchange for the date command tag</a></ul></div><div class=post-footer><div class=post-tags><a href=https://learnbyexample.github.io/tags/linux/>#linux</a><a href=https://learnbyexample.github.io/tags/command-line/>#command-line</a><a href=https://learnbyexample.github.io/tags/date/>#date</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=next href=https://learnbyexample.github.io/mini/cli-text-editing-with-ed/>CLI text editing with ed →</a><br></div><hr color=#e6e6e6><p>📰 Use <a href=https://learnbyexample.github.io/atom.xml>this link</a> for the Atom feed. <br> ✅ Follow me on <a href=https://twitter.com/learn_byexample>Twitter</a>, <a href=https://github.com/learnbyexample>GitHub</a> and <a href=https://www.youtube.com/c/learnbyexample42>Youtube</a> for interesting tech nuggets. <br> 📧 Subscribe to <a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>learnbyexample weekly</a> for programming resources, tips, tools, free ebooks and more (free newsletter, delivered every Friday).<hr color=#e6e6e6></div></article></div></main></div><script src=https://learnbyexample.github.io/even.js></script>
56+
</span></code></pre><br><h2 id=resource-links>Resource links</h2><ul><li><a href=https://www.gnu.org/software/coreutils/manual/coreutils.html#date-invocation>GNU date command manual</a><li><a href=https://www.gnu.org/software/coreutils/manual/coreutils.html#Examples-of-date>"Examples of date" section from the manual</a><li><a href="https://unix.stackexchange.com/questions/tagged/date?tab=Votes">Top voted Q&A on unix.stackexchange for the date command tag</a></ul></div><div class=post-footer><div class=post-tags><a href=https://learnbyexample.github.io/tags/linux/>#linux</a><a href=https://learnbyexample.github.io/tags/command-line/>#command-line</a><a href=https://learnbyexample.github.io/tags/date/>#date</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=next href=https://learnbyexample.github.io/mini/cli-text-editing-with-ed/>CLI text editing with ed →</a><br></div><hr color=#e6e6e6><p>📰 Use <a href=https://learnbyexample.github.io/atom.xml>this link</a> for the Atom feed. <br> ✅ Follow me on <a href=https://twitter.com/learn_byexample>Twitter</a>, <a href=https://github.com/learnbyexample>GitHub</a> and <a href=https://www.youtube.com/c/learnbyexample42>Youtube</a> for interesting tech nuggets. <br> 📧 Subscribe to <a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>learnbyexample weekly</a> for programming resources, tips, tools, free ebooks and more (free newsletter, delivered every Friday).<hr color=#e6e6e6></div></article></div></main></div><script src=https://learnbyexample.github.io/even.js></script>

sitemap.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
</url>
149149
<url>
150150
<loc>https://learnbyexample.github.io/mini/linux-date-command-examples/</loc>
151-
<lastmod>2024-08-13</lastmod>
151+
<lastmod>2025-01-28</lastmod>
152152
</url>
153153
<url>
154154
<loc>https://learnbyexample.github.io/mini/perl-oneliner-articles/</loc>

0 commit comments

Comments
 (0)