aboutsummaryrefslogtreecommitdiff
path: root/src/blog
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2022-05-29 12:43:19 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2022-05-29 12:43:19 +0200
commit3eb7941bc731887864fc0df25be6eab981f67034 (patch)
treefd883f9f8fbb59d31616b48a9433e50f646d8477 /src/blog
parentf7a754096df43f2a59377a4d59bf4c1d4a61f0cb (diff)
downloadsebastiano.tronto.net-3eb7941bc731887864fc0df25be6eab981f67034.tar.gz
sebastiano.tronto.net-3eb7941bc731887864fc0df25be6eab981f67034.zip
Added blog post
Diffstat (limited to 'src/blog')
-rw-r--r--src/blog/2022-05-29-man/man.md248
-rw-r--r--src/blog/blog.md1
-rw-r--r--src/blog/feed.xml7
3 files changed, 256 insertions, 0 deletions
diff --git a/src/blog/2022-05-29-man/man.md b/src/blog/2022-05-29-man/man.md
new file mode 100644
index 0000000..babdaaf
--- /dev/null
+++ b/src/blog/2022-05-29-man/man.md
@@ -0,0 +1,248 @@
1# The man page reading club: man(1)
2
3I have been using Linux as my main operating system for the
4last 14 years, and as my only one for the last 10. Needless
5to say, I really like it. However, at the end of last year I
6have decided to use [OpenBSD](https://www.openbsd.org/) for my
7[VPS](https://en.wikipedia.org/wiki/Virtual_private_server). I had 3
8main reasons (spoiler: security is not one of them):
9
10* It is still UNIX: most things I am used to do with the Linux command
11 line work exactly the same in other UNIX-like operating systems, so
12 I would not have to learn everything from scratch.
13* Comprehensive base installation: a lot of things I needed,
14 such as an http server, were already included in the base system.
15 This results in a great consistency with the rest of the OS,
16 for example in terms of configuration file location and syntax.
17* Local documentation, i.e. manual pages: having a well-written documentation
18 attached to any piece of software you install is something that I find
19 very valuable. I do not like the idea of having to rely on external
20 documentation, which may or may not be specific to the OS I am using
21 and to the specific version of the software I have installed, and
22 googling for solutions is always a hit or miss.
23
24As I was expecting, after some time using it I was really pleased with
25the quality of OpenBSD's manual pages, to the point that I am sometimes
26using them (by ssh-ing into my server) also when I am working or writing
27[scripts](https://git.tronto.net/scripts) for my Linux machine.
28
29So I thought that it would be nice to take once in a while one of these
30manual pages, read it, and share what I learned with other people.
31Hence I decided to start this blog-series: "The man page reading club".
32
33## Nuclear Apocalypse
34
35I tried to find a nice setting for this series, a funny story to introduce
36each of these technical posts, but I could not come up with any good idea.
37Luckily, a couple of weeks ago I read the short post
38[OpenBSD is the Perfect OS post Nuclear Apocalypse](https://confuzeus.com/shorts/openbsd-nuclear-apocalypse/)
39and I found it to be exactly what I was looking for!
40
41*So here you are, in a cozy underground bunker during a Nuclear
42Apocalypse. There is enough food and electricity for everyone, but
43of course no Internet. After a couple of days of social chit-chat
44with your new roommates you find out that you have pretty much
45nothing in common with them, so you turn to your trusty laptop and
46you install OpenBSD 7.1 - the last version released before the apocalypse.*
47
48```
49From: deraadt@do-not-reply.openbsd.org (Theo de Raadt)
50Subject: Welcome to OpenBSD 7.1!
51```
52
53*Says your screen, after you login and type `mail`.*
54
55```
56For more information on how to set up your OpenBSD system, refer to the
57"afterboot" man page.
58```
59
60*The what?*
61
62```
63If you are not familiar with how to read man pages, type "man man"
64at a shell prompt and read the entire thing.
65```
66
67*Sounds like a good idea, let's do it!*
68
69```
70$ man man
71```
72
73## man(1)
74
75*Follow along at [man.openbsd.org](https://man.openbsd.org/OpenBSD-7.1/man)*
76
77The first interesting thing we see in this manual page is a thing called
78*synopsis*:
79
80```
81SYNOPSIS
82 man [-acfhklw] [-C file] [-M path] [-m path] [-S subsection]
83 [[-s] section] name ...
84```
85
86This explains how to invoke the `man` command. The parts within square brackets
87are optional, and the other words such as `path` and `section` are going to be
88explained later in this page.
89
90A short description the tells us that `man` is used to display manual pages.
91It is followed by a detailed explanation of what each option does.
92Let's look at some of them!
93
94```
95-c Copy the manual page to the standard output instead of using
96 less(1) to paginate it. This is done by default if the standard
97 output is not a terminal device.
98```
99This option is not very interesting to use because of the last sentence:
100it is the default behavior when you need it (for example, when you pipe
101the output to another program). It is however interesting to read its
102description, because it reveals a little detail of how `man` works.
103Namely, that every time we open a man page we are also calling `less`!
104
105```
106-h Display only the SYNOPSIS lines of the requested manual pages.
107 Implies -a and -c.
108```
109
110This can be useful for commands with a more complicated syntax.
111
112```
113-k A synonym for apropos(1). Instead of name, an expression can be
114 provided using the syntax described in the apropos(1) manual.
115 By default, it displays the header lines of all matching pages.
116```
117
118This sounds like some kind of search function, like a post-nuclear Google.
119Indeed, `man apropos` tells us:
120
121```
122NAME
123 apropos, whatis - search manual page databases
124```
125
126The page `apropos(1)` is worth a read, but I won't write a dedicated post.
127This utility supports searching by regular expressions and by "`mdoc` macros".
128If you don't know what they are, worry not: it is all well explained in
129`apropos(1)`. The page also contains a lot of examples, which is always
130appreciated.
131
132Now back to `man man`!
133
134```
135[-s] section
136 Only select manuals from the specified section. The currently
137 available sections are:
138
139 1 General commands (toold and utilities).
140 2 System calls and error numbers.
141 3 Library functions.
142 3p perl(1) programmer's reference guide.
143 4 Device drivers.
144 5 File formats.
145 6 Games.
146 7 Miscellaneous information.
147 8 System maintenance and operation commands.
148 9 Kernel internals.
149```
150Manual pages are divided into sections: they are the mysterious numbers in
151parentheses after a command's name, like in `less(1)`. There can be pages
152with the same name in different sections, and with this option you can specify
153which one you want. For example `man printf` shows the `printf(1)` page, for
154the UNIX command with the same name, while `man -s 3 printf` shows the manual
155page for the `printf()` C library function. The syntax for this option is
156slightly unusual in that the `-s` itself is optional: `man 3 printf` does
157the same as `man -s 3 printf`.
158
159One might be tempted to think that if no section is specified, the page in the
160lowest-number section is shown. However:
161
162```
163Within each directory, the search procedes according to the following list
164of sections: 1, 8, 6, 2, 3, 5, 7, 4, 9, 3p. The first match found is shown.
165```
166
167The `man` program also behaves differently depending on the value of
168some environment variables. For example
169
170```
171MANPAGER Any non-empty value of the environment variable MANPAGER is
172 used instead of the standard pagination program, less(1).
173 ...
174
175PAGER Specifies the pagination program to use when MANPAGER is not
176 defined. If neither PAGER nor MANPAGER is defined, less(1) is
177 used.
178```
179
180It looks like the variable `MANPAGER` is read only by `man`, while `PAGER`
181may be understood by other commands as well. But how do we set environment
182variables? One way to do this is shown in the `EXAMPLES` section:
183
184```
185Read a typeset page in a PDF viewer:
186
187 $ MANPAGER=mupdf man -T pdf lpd
188```
189
190Now you should complain, because I did not tell you about the `-T` option!
191In fact I skipped this line:
192
193```
194The options -IKOTW are also supported and are documented in mandoc(1).
195```
196
197A quick look at the `mandoc(1)` page tell us that
198the most interesting of these options are `-T`, which we have just seen,
199and `-O`, which allows to tune some formatting settings. For example
200```
201man -O width=50 man
202```
203shows you a man page using only 50 columns, while
204```
205man -O tag=EXAMPLES man
206```
207shows you the `man(1)` page, but starting from the `EXAMPLES` section
208(you can still scroll back up to the beginning of the page).
209
210Back to `man man`.
211
212```
213STANDARDS
214 The man utility is compliant with the IEEE Std 1003.1-2008 ("POSIX.1")
215 specification.
216
217 The flags [-aCcfhIKlMmOSsTWw], as well as the environment variables
218 MACHINE, MANPAGER, and MANPATH, are extensions to that specification.
219```
220
221This means that all of the stuff we read in this manual page, except for the
222very basic functionality of `man` - showing manual pages - is not
223POSIX-standard, and might be different on other systems. Be sure to check
224what your version of `man` does before assuming that it will behave the same
225as the OpenBSD one!
226I find it very nice that the OpenBSD man pages always tell you which parts
227are standard (and thus you can expect to work in the same way on other
228UNIX-like OSes) and which are OpenBSD-specific. It makes writing
229portable scripts much easier!
230
231## Conclusions
232
233`man` is a straightforward utility and most of the time you are just going
234to use it by typing `man command`. However, reading this page I was still
235able to learn new stuff - such as the `-h` and `-O` options and the fact
236that `apropos` supports searching by regular expressions and tags.
237I hope you have learnt something new too.
238
239As you can see I have skipped a lot of things, including all the parts
240related to the `MANPATH`. This post does not want to
241be a comprehensive tutorial on the `man` command, just a
242survey of the subjectively most useful parts of the manual.
243
244For the next post I will either take one of the pages that was referenced
245here, such as `less(1)`, or dive into more exciting stuff with something
246like `sh(1)`.
247
248Stay tuned!
diff --git a/src/blog/blog.md b/src/blog/blog.md
index 2026656..34853b1 100644
--- a/src/blog/blog.md
+++ b/src/blog/blog.md
@@ -2,4 +2,5 @@
2 2
3[RSS Feed](feed.xml) 3[RSS Feed](feed.xml)
4 4
5* 2022-05-29 [The man page reading club: man(1)](2022-05-29-man)
5* 2022-05-21 [Blogs](2022-05-21-blogs) 6* 2022-05-21 [Blogs](2022-05-21-blogs)
diff --git a/src/blog/feed.xml b/src/blog/feed.xml
index 1ecace0..6693b07 100644
--- a/src/blog/feed.xml
+++ b/src/blog/feed.xml
@@ -9,6 +9,13 @@ Thoughts about software, computers and whatever I feel like sharing
9</description> 9</description>
10 10
11<item> 11<item>
12<title>The man page reading club: man(1)</title>
13<link>https://sebastiano.tronto.net/blog/2022-05-29-man</link>
14<description>The man page reading club: man(1)</description>
15<pubDate>2022-05-29</pubDate>
16</item>
17
18<item>
12<title>Blogs</title> 19<title>Blogs</title>
13<link>https://sebastiano.tronto.net/blog/2022-05-21-blogs</link> 20<link>https://sebastiano.tronto.net/blog/2022-05-21-blogs</link>
14<description>Blogs</description> 21<description>Blogs</description>

Generated with cgit - Back to sebastiano.tronto.net