diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2022-05-29 12:43:19 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2022-05-29 12:43:19 +0200 |
| commit | 3eb7941bc731887864fc0df25be6eab981f67034 (patch) | |
| tree | fd883f9f8fbb59d31616b48a9433e50f646d8477 | |
| parent | f7a754096df43f2a59377a4d59bf4c1d4a61f0cb (diff) | |
| download | sebastiano.tronto.net-3eb7941bc731887864fc0df25be6eab981f67034.tar.gz sebastiano.tronto.net-3eb7941bc731887864fc0df25be6eab981f67034.zip | |
Added blog post
| -rw-r--r-- | src/blog/2022-05-29-man/man.md | 248 | ||||
| -rw-r--r-- | src/blog/blog.md | 1 | ||||
| -rw-r--r-- | src/blog/feed.xml | 7 |
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 | |||
| 3 | I have been using Linux as my main operating system for the | ||
| 4 | last 14 years, and as my only one for the last 10. Needless | ||
| 5 | to say, I really like it. However, at the end of last year I | ||
| 6 | have decided to use [OpenBSD](https://www.openbsd.org/) for my | ||
| 7 | [VPS](https://en.wikipedia.org/wiki/Virtual_private_server). I had 3 | ||
| 8 | main 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 | |||
| 24 | As I was expecting, after some time using it I was really pleased with | ||
| 25 | the quality of OpenBSD's manual pages, to the point that I am sometimes | ||
| 26 | using 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 | |||
| 29 | So I thought that it would be nice to take once in a while one of these | ||
| 30 | manual pages, read it, and share what I learned with other people. | ||
| 31 | Hence I decided to start this blog-series: "The man page reading club". | ||
| 32 | |||
| 33 | ## Nuclear Apocalypse | ||
| 34 | |||
| 35 | I tried to find a nice setting for this series, a funny story to introduce | ||
| 36 | each of these technical posts, but I could not come up with any good idea. | ||
| 37 | Luckily, 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/) | ||
| 39 | and 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 | ||
| 42 | Apocalypse. There is enough food and electricity for everyone, but | ||
| 43 | of course no Internet. After a couple of days of social chit-chat | ||
| 44 | with your new roommates you find out that you have pretty much | ||
| 45 | nothing in common with them, so you turn to your trusty laptop and | ||
| 46 | you install OpenBSD 7.1 - the last version released before the apocalypse.* | ||
| 47 | |||
| 48 | ``` | ||
| 49 | From: deraadt@do-not-reply.openbsd.org (Theo de Raadt) | ||
| 50 | Subject: Welcome to OpenBSD 7.1! | ||
| 51 | ``` | ||
| 52 | |||
| 53 | *Says your screen, after you login and type `mail`.* | ||
| 54 | |||
| 55 | ``` | ||
| 56 | For more information on how to set up your OpenBSD system, refer to the | ||
| 57 | "afterboot" man page. | ||
| 58 | ``` | ||
| 59 | |||
| 60 | *The what?* | ||
| 61 | |||
| 62 | ``` | ||
| 63 | If you are not familiar with how to read man pages, type "man man" | ||
| 64 | at 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 | |||
| 77 | The first interesting thing we see in this manual page is a thing called | ||
| 78 | *synopsis*: | ||
| 79 | |||
| 80 | ``` | ||
| 81 | SYNOPSIS | ||
| 82 | man [-acfhklw] [-C file] [-M path] [-m path] [-S subsection] | ||
| 83 | [[-s] section] name ... | ||
| 84 | ``` | ||
| 85 | |||
| 86 | This explains how to invoke the `man` command. The parts within square brackets | ||
| 87 | are optional, and the other words such as `path` and `section` are going to be | ||
| 88 | explained later in this page. | ||
| 89 | |||
| 90 | A short description the tells us that `man` is used to display manual pages. | ||
| 91 | It is followed by a detailed explanation of what each option does. | ||
| 92 | Let'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 | ``` | ||
| 99 | This option is not very interesting to use because of the last sentence: | ||
| 100 | it is the default behavior when you need it (for example, when you pipe | ||
| 101 | the output to another program). It is however interesting to read its | ||
| 102 | description, because it reveals a little detail of how `man` works. | ||
| 103 | Namely, 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 | |||
| 110 | This 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 | |||
| 118 | This sounds like some kind of search function, like a post-nuclear Google. | ||
| 119 | Indeed, `man apropos` tells us: | ||
| 120 | |||
| 121 | ``` | ||
| 122 | NAME | ||
| 123 | apropos, whatis - search manual page databases | ||
| 124 | ``` | ||
| 125 | |||
| 126 | The page `apropos(1)` is worth a read, but I won't write a dedicated post. | ||
| 127 | This utility supports searching by regular expressions and by "`mdoc` macros". | ||
| 128 | If 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 | ||
| 130 | appreciated. | ||
| 131 | |||
| 132 | Now 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 | ``` | ||
| 150 | Manual pages are divided into sections: they are the mysterious numbers in | ||
| 151 | parentheses after a command's name, like in `less(1)`. There can be pages | ||
| 152 | with the same name in different sections, and with this option you can specify | ||
| 153 | which one you want. For example `man printf` shows the `printf(1)` page, for | ||
| 154 | the UNIX command with the same name, while `man -s 3 printf` shows the manual | ||
| 155 | page for the `printf()` C library function. The syntax for this option is | ||
| 156 | slightly unusual in that the `-s` itself is optional: `man 3 printf` does | ||
| 157 | the same as `man -s 3 printf`. | ||
| 158 | |||
| 159 | One might be tempted to think that if no section is specified, the page in the | ||
| 160 | lowest-number section is shown. However: | ||
| 161 | |||
| 162 | ``` | ||
| 163 | Within each directory, the search procedes according to the following list | ||
| 164 | of sections: 1, 8, 6, 2, 3, 5, 7, 4, 9, 3p. The first match found is shown. | ||
| 165 | ``` | ||
| 166 | |||
| 167 | The `man` program also behaves differently depending on the value of | ||
| 168 | some environment variables. For example | ||
| 169 | |||
| 170 | ``` | ||
| 171 | MANPAGER Any non-empty value of the environment variable MANPAGER is | ||
| 172 | used instead of the standard pagination program, less(1). | ||
| 173 | ... | ||
| 174 | |||
| 175 | PAGER 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 | |||
| 180 | It looks like the variable `MANPAGER` is read only by `man`, while `PAGER` | ||
| 181 | may be understood by other commands as well. But how do we set environment | ||
| 182 | variables? One way to do this is shown in the `EXAMPLES` section: | ||
| 183 | |||
| 184 | ``` | ||
| 185 | Read a typeset page in a PDF viewer: | ||
| 186 | |||
| 187 | $ MANPAGER=mupdf man -T pdf lpd | ||
| 188 | ``` | ||
| 189 | |||
| 190 | Now you should complain, because I did not tell you about the `-T` option! | ||
| 191 | In fact I skipped this line: | ||
| 192 | |||
| 193 | ``` | ||
| 194 | The options -IKOTW are also supported and are documented in mandoc(1). | ||
| 195 | ``` | ||
| 196 | |||
| 197 | A quick look at the `mandoc(1)` page tell us that | ||
| 198 | the most interesting of these options are `-T`, which we have just seen, | ||
| 199 | and `-O`, which allows to tune some formatting settings. For example | ||
| 200 | ``` | ||
| 201 | man -O width=50 man | ||
| 202 | ``` | ||
| 203 | shows you a man page using only 50 columns, while | ||
| 204 | ``` | ||
| 205 | man -O tag=EXAMPLES man | ||
| 206 | ``` | ||
| 207 | shows 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 | |||
| 210 | Back to `man man`. | ||
| 211 | |||
| 212 | ``` | ||
| 213 | STANDARDS | ||
| 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 | |||
| 221 | This means that all of the stuff we read in this manual page, except for the | ||
| 222 | very basic functionality of `man` - showing manual pages - is not | ||
| 223 | POSIX-standard, and might be different on other systems. Be sure to check | ||
| 224 | what your version of `man` does before assuming that it will behave the same | ||
| 225 | as the OpenBSD one! | ||
| 226 | I find it very nice that the OpenBSD man pages always tell you which parts | ||
| 227 | are standard (and thus you can expect to work in the same way on other | ||
| 228 | UNIX-like OSes) and which are OpenBSD-specific. It makes writing | ||
| 229 | portable scripts much easier! | ||
| 230 | |||
| 231 | ## Conclusions | ||
| 232 | |||
| 233 | `man` is a straightforward utility and most of the time you are just going | ||
| 234 | to use it by typing `man command`. However, reading this page I was still | ||
| 235 | able to learn new stuff - such as the `-h` and `-O` options and the fact | ||
| 236 | that `apropos` supports searching by regular expressions and tags. | ||
| 237 | I hope you have learnt something new too. | ||
| 238 | |||
| 239 | As you can see I have skipped a lot of things, including all the parts | ||
| 240 | related to the `MANPATH`. This post does not want to | ||
| 241 | be a comprehensive tutorial on the `man` command, just a | ||
| 242 | survey of the subjectively most useful parts of the manual. | ||
| 243 | |||
| 244 | For the next post I will either take one of the pages that was referenced | ||
| 245 | here, such as `less(1)`, or dive into more exciting stuff with something | ||
| 246 | like `sh(1)`. | ||
| 247 | |||
| 248 | Stay 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> |
