At least on my system (Arch Linux, man-db 2.9.4, Firefox 88.0), man
creates a temporary directory in /tmp/
, writes the generated HTML file in it, invokes the browser with the HTML file as an argument and, when the browser process exits, removes the temporary directory (to clean things up, I guess).
While this creates no issue with some browsers (e.g. Lynx), a race condition may occur with others (Firefox, in my case; I also briefly tested Chromium, getting similar results). As far as I can see, the HTML file is correctly opened if man
opens a new browser window. On the other hand, if the man page is opened as a new tab in an existing browser window, the browser process started by man
returns early and the file is already gone when a different browser process tries to read it.
I see no man
option aimed at preventing the temporary HTML file from being deleted. But, noting that the argument to the -H
/--html
option (or, equivalently, the value of the BROWSER
environment variable) can be a shell command, a quick workaround may be:
BROWSER='firefox %s; sleep 5' man -H 3 free
(sleep
gives Firefox time to load the page before the file is deleted; of course, it will be impossible to reload it).
Or, if you are willing to implement your own mechanism for deleting the temporary HTML files:
BROWSER='cp %s /path/to/file.html; firefox /path/to/file.html' man -H 3 free
(This ignores other assets that may be generated alongside the main .html
file, which may therefore be rendered incorrectly).
Or, if you are fine with keeping the temporary directories (e.g. you do not generate lots of them, your /tmp
is volatile and your system is rebooted regularly enough):
BROWSER='firefox %s && false' man -H 3 free
(The temporary directory is not deleted when the browser command returns an error to man
; as a drawback, an error message is printed because man
thinks the browser could not be opened).
Note, also, that the TMP
environment variable can be used to tell man
where to create its temporary data.
Finally, the chosen workaround can be conveniently made into an alias or a function along the lines of:
alias man='BROWSER="${BROWSER:-firefox} %s && false" man'
See also, for alternative ways to view man pages as HTML: