Skip to content

Commit a466136

Browse files
mini blog post for the linux date command
1 parent a5cc7c8 commit a466136

File tree

10 files changed

+110
-7
lines changed

10 files changed

+110
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ I'm addicted to reading fantasy/sci-fi books, so I have a [blog](https://learnby
6161

6262
## Mini blog posts
6363

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

atom.xml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,69 @@
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>2024-07-03T00:00:00+00:00</updated>
8+
<updated>2024-07-31T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
10+
<entry xml:lang="en">
11+
<title>Basic examples for the Linux date command</title>
12+
<published>2024-07-31T00:00:00+00:00</published>
13+
<updated>2024-07-31T00:00:00+00:00</updated>
14+
<link rel="alternate" href="https://learnbyexample.github.io/mini/linux-date-command-examples/" type="text/html"/>
15+
<id>https://learnbyexample.github.io/mini/linux-date-command-examples/</id>
16+
<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;
17+
&lt;p&gt;There&#x27;ll also be learning resources linked at the end of the post.&lt;&#x2F;p&gt;
18+
&lt;br&gt;
19+
&lt;h2 id=&quot;really-basic-examples&quot;&gt;Really basic examples&lt;&#x2F;h2&gt;
20+
&lt;p&gt;The &lt;code&gt;date&lt;&#x2F;code&gt; command by itself shows the current time. But that&#x27;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 &lt;code&gt;-s&lt;&#x2F;code&gt; option?&lt;&#x2F;p&gt;
21+
&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;# use the -u option for UTC (Coordinated Universal Time)
22+
&lt;&#x2F;span&gt;&lt;span&gt;$ date
23+
&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
24+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
25+
&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;
26+
&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
27+
&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
28+
&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
29+
&lt;&#x2F;span&gt;&lt;span&gt;
30+
&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:#c49a39;&quot;&gt;&#x2F;%m&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;%&lt;&#x2F;span&gt;&lt;span&gt;d
31+
&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;&#x2F;&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;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;31
32+
&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&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
33+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;24&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
34+
&lt;&#x2F;span&gt;&lt;span&gt;
35+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# use &amp;#39;b&amp;#39; and &amp;#39;B&amp;#39; for month names
36+
&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&gt;a
37+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;Wed
38+
&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;A
39+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;Wednesday
40+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
41+
&lt;p&gt;You can use &lt;code&gt;%x&lt;&#x2F;code&gt; to get the locale representation:&lt;&#x2F;p&gt;
42+
&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&gt;$ date &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;%x
43+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;31&#x2F;07&#x2F;24
44+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
45+
&lt;p&gt;For hours, minutes and seconds:&lt;&#x2F;p&gt;
46+
&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 +%T
47+
&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:#b3933a;&quot;&gt;H:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;%&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;M:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;%&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;S
48+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;16&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;00&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;32
49+
&lt;&#x2F;span&gt;&lt;span&gt;
50+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# same as: date +%Y-%m-%dT%H:%M:%S%:z
51+
&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;Iseconds
52+
&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&gt;31T16&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;09&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;27&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;05&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;30
53+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
54+
&lt;br&gt;
55+
&lt;h2 id=&quot;displaying-and-converting-epoch-seconds&quot;&gt;Displaying and converting epoch seconds&lt;&#x2F;h2&gt;
56+
&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;# total seconds since the epoch (1970-01-01 00:00:00 UTC)
57+
&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:#d07711;&quot;&gt;%s
58+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;1722422393
59+
&lt;&#x2F;span&gt;&lt;span&gt;
60+
&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&gt;d @&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;1722422393 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#aeb52b;&quot;&gt;%F %T&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39;
61+
&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 16&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;09&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
62+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
63+
&lt;br&gt;
64+
&lt;h2 id=&quot;resource-links&quot;&gt;Resource links&lt;&#x2F;h2&gt;
65+
&lt;ul&gt;
66+
&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;
67+
&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;
68+
&lt;&#x2F;ul&gt;
69+
</content>
70+
</entry>
1071
<entry xml:lang="en">
1172
<title>Linux Command Line Computing book announcement</title>
1273
<published>2024-05-29T00:00:00+00:00</published>

mini/cli-text-editing-with-ed/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@
4646
</span><span>green
4747
</span><span>yellow
4848
</span><span>black
49-
</span></code></pre><h2 id=resource-links>Resource links</h2><ul><li><a href=https://blog.sanctum.geek.nz/actually-using-ed/>Actually using ed</a><li><a href=https://raymii.org/s/tutorials/ed_cheatsheet.html>ed cheatsheet</a><li><a href=https://jvns.ca/blog/2018/05/11/batch-editing-files-with-ed/>Batch editing files with ed</a><li><a href=https://en.wikipedia.org/wiki/Ed_(text_editor)>wikipedia entry for the ed command</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/ed/>#ed</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=next href=https://learnbyexample.github.io/mini/cli-computing-sales/>Computing from the Command Line: sales report →</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>
49+
</span></code></pre><h2 id=resource-links>Resource links</h2><ul><li><a href=https://blog.sanctum.geek.nz/actually-using-ed/>Actually using ed</a><li><a href=https://raymii.org/s/tutorials/ed_cheatsheet.html>ed cheatsheet</a><li><a href=https://jvns.ca/blog/2018/05/11/batch-editing-files-with-ed/>Batch editing files with ed</a><li><a href=https://en.wikipedia.org/wiki/Ed_(text_editor)>wikipedia entry for the ed command</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/ed/>#ed</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=previous href=https://learnbyexample.github.io/mini/linux-date-command-examples/>← Basic examples for the Linux date command</a><br><p><a class=next href=https://learnbyexample.github.io/mini/cli-computing-sales/>Computing from the Command Line: sales report →</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>

0 commit comments

Comments
 (0)