15

I've a largish man page (psql) that I'm trying to digest. I've tried redirecting the output of man to a file, but the output confuses LibreOffice enough that whole pages are missing, even if I arrange that the lines wrap properly (I set my window width to 79 before I issue the man command then have LibreOffice change the font size to 10 pt.)

So: I could use a different word processor, I guess. Or maybe there are better commands to use than man itself. Or maybe there's a way to bypass LibreOffice and send it directly to my printer (a Brother monochrome laser printer).

In the end, I just need something readable and physical so that I can mark it up with highlighters and write on it.

8
  • 9
    Most man pages are available on the Internet as html. Google the man page you are trying to print. Then print from the browser.
    – user68186
    Commented Mar 29, 2022 at 0:00
  • @user68186 I'm embarrassed I didn't think of that, but when I tried it just now, it only printed a single page. Not sure how to get it to paginate and still retain the formatting.
    – 4dummies
    Commented Mar 29, 2022 at 0:06
  • 5
    There is also the man -t option for outputting in postscript format for a printer. Commented Mar 29, 2022 at 0:33
  • 2
    Related: Is there a way to print info/man pages to PDF? Commented Mar 29, 2022 at 11:47
  • 1
    I'm baffled that man | lpr didn't work.
    – Joshua
    Commented Mar 31, 2022 at 4:39

5 Answers 5

19

You can output the manpage in html using command options.

example to view the manpage for nano:

man --html=firefox nano

use:

man --help

for more information.

Note that you must have the groff package installed. Having the groff command alone from the groff-base package is not enough.

Alternatively, you can google "ubuntu manpage packagename" replacing "packagename" with the actual packagename to view the Ubuntu manpages online.

10
  • 6
    "use man --help for more information."- or man man.
    – rolinger
    Commented Mar 30, 2022 at 13:01
  • 1
    Note that one must have the groff package installed for this to work, otherwise man will exit with an error status and a cryptic error message. Things are confusing because the executable groff may already be installed but that alone won't be enough. I've submitted an edit for the answer that adds this information.
    – undercat
    Commented Mar 31, 2022 at 6:09
  • It appears this doesn't work on 18.04 :( I found a solution but not sure if the security implications are worth it and I'd have to look into it further.
    – mchid
    Commented Mar 31, 2022 at 12:18
  • @mchid Interesting, my edit was for 20.04, but I assumed other recent versions wouldn't differ in that respect.
    – undercat
    Commented Apr 1, 2022 at 0:48
  • 1
    @undercat Yeah, it's weird. It's always worked on older versions and I used to have an alias set. For now, I'll just use a script with: man2html $(man -w $1) > $HOME/$1.html; firefox $HOME/$1.html & instead
    – mchid
    Commented Apr 1, 2022 at 14:34
18

For a PDF:

man -t psql > psql.ps
ps2pdf psql.ps
2
  • 10
    You can avoid the temporary file by doing man -t psql | ps2pdf - psql.pdf. Commented Mar 30, 2022 at 14:31
  • @flndr Perfect answer to my question
    – 4dummies
    Commented Apr 5, 2022 at 18:00
5

A package called man2html-base is already available in the repositories and its job is to convert man pages to an HTML page.

First, you need to install it like so:

sudo apt install man2html-base

Then, you need to find the main compressed man page file for the desired package by running a tool like whereis... taking nano as an example it would be done like so:

whereis nano

Look in the output for a .gz archive file that has got man in its path like:

/usr/share/man/man1/nano.1.gz

Or use man -w ( Thank you to @mchid's comment ) to find the file like so:

man -w nano

Finally, once you find that file, you can convert it to HTML like so:

man2html /usr/share/man/man1/nano.1.gz > ~/nano.html

the > ~/nano.html part will redirect the output to a file called nano.html in your home directory.

Notice: You can try auto detecting the man page file and converting it in one step utilizing bash command substitution like so:

man2html "$(man -w nano)" > ~/nano.html
11
  • man -t should be the way to go. Commented Mar 29, 2022 at 20:09
  • well man -t nano|ps2txt > nano.txt anyway.
    – mckenzm
    Commented Mar 29, 2022 at 23:23
  • 1
    @mckenzm That is possible as well as sending the output to evince like so man -t nano | tee - | evince - then printing or saving it from there ... evince comes preinstalled with Ubuntu.
    – Raffa
    Commented Mar 30, 2022 at 15:38
  • 1
    @ThorbjørnRavnAndersen I do not see why you think it is "the way to go"! ... It's just a way of doing it and there are many other ways ... man2html is widely used especially to create online copies of man pages plus it creates indexes which you don't get with man -t
    – Raffa
    Commented Mar 30, 2022 at 15:42
  • 1
    Alternatively, you can also use man -w nano to find the path to the compressed file.
    – mchid
    Commented Mar 31, 2022 at 16:34
3

To obtain a printed copy of a man page, say for psql, use:

man -t psql | lpr

Or as @4dummies suggests, if your printer supports duplexing:

man -t psql | lpr -o sides=two-sided-long-edge

One could even create a bash function for convenience:

prman() {
  man -t "$1" | lpr -o sides=two-sided-long-edge
}

and then say:

prman psql

1
  • Change that to "man -t psql | lpr -o sides=two-sided-long-edge" and you have a winner. it's just harder to remember. I suppose I could write a bash alias for that.
    – 4dummies
    Commented Apr 6, 2022 at 1:19
1

If you happen to have any KDE applications installed, one clever little trick is to make sure you have the kio-extras and kde-cli-tools packages installed and run this command

kioclient5 copy man:psql file://$HOME/psql.html

It's intended to allow you to load man:psql in something like KDE's Konqueror web browser/file manager hybrid but kio_man will work for anything that supports loading from arbitrary KIOSlaves for its Open File functionality.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .