14

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.

4dummies
  • 452
  • 4
  • 19

5 Answers5

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.

mchid
  • 43,546
  • 8
  • 97
  • 150
  • 6
    "use man --help for more information."- or man man. – rolinger Mar 30 '22 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 Mar 31 '22 at 06: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 Mar 31 '22 at 12:18
  • @mchid Interesting, my edit was for 20.04, but I assumed other recent versions wouldn't differ in that respect. – undercat Apr 01 '22 at 00:48
  • @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 Apr 01 '22 at 14:34
  • Ummm. I have groff, but not the whole package. How do I get that? Moreover, going through HTML to get to Postscript seems just weird. But then going to PDF should work, because I know I can print those. – 4dummies Apr 05 '22 at 17:54
  • @4dummies You can install the full version of groff by running sudo apt install groff. As mentioned, groff-base is installed by default and is a dependency of groff. Also, both firefox and google allow you to print using CTRL+P and you can use the "print to file" option to export as a PDF. – mchid Apr 07 '22 at 01:59
  • @4dummies If you're getting an error on 18.04, it's because of a security issue and apparmor. The best way to work around that would be to use the script I provided in the other comment or you can run it as a command by replacing $1 with psql like in this example: man2html $(man -w psql) > $HOME/psql.html; firefox $HOME/psql.html & – mchid Apr 07 '22 at 02:06
  • @4dummies apt-cache search groff | grep groff – mchid Apr 07 '22 at 02:20
  • @4dummies https://unix.stackexchange.com/questions/594081/man-html-and-man-gxditview-exit-with-errors – mchid Apr 07 '22 at 02:25
18

For a PDF:

man -t psql > psql.ps
ps2pdf psql.ps
flndr
  • 301
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
Raffa
  • 32,237
  • man -t should be the way to go. – Thorbjørn Ravn Andersen Mar 29 '22 at 20:09
  • well man -t nano|ps2txt > nano.txt anyway. – mckenzm Mar 29 '22 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 Mar 30 '22 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 Mar 30 '22 at 15:42
  • @raffa -t is available everywhere for historic reasons. —html is not available on non-gnu systems. – Thorbjørn Ravn Andersen Mar 31 '22 at 07:53
  • @ThorbjørnRavnAndersen Without me delving into an extended discussion of this subject, I would like to express that I value your opinion and your concern ... However this site is askubuntu.com where we help Ubuntu users to get things don on their systems with whatever right means available and then we let them choose what suits them the best... I hope you understand. – Raffa Mar 31 '22 at 11:07
  • @raffa I thought you would appreciate an approach that did not require a user to "Look in the output for a .gz archive file". And works everywhere even. My bad. – Thorbjørn Ravn Andersen Mar 31 '22 at 11:56
  • @ThorbjørnRavnAndersen I appreciate your presence and your comments :) and I hope that you might add an answer here because you clearly have the knowledge ... but man -t is already mentioned in the answer by @flndr ... not that I don't know it but it was already there when I wrote my answer ... plus diversity is good – Raffa Mar 31 '22 at 12:26
  • 1
    Alternatively, you can also use man -w nano to find the path to the compressed file. – mchid Mar 31 '22 at 16:34
  • @Raffa Your command is misguiding a bit because use of - as the filename suggests that evince is reading from stdin, which it actually doesn't. Your command creates an ordinary file with the name - in the current dir with the postscript output (and that is read by evince), which may be an unwanted side effect. I would rather explicitly use a file in /tmp and get rid of pipe, which isn't actually used. Something like man -t nano >/tmp/mantmp && evince /tmp/mantmp. – raj Mar 31 '22 at 20:24
  • @raj True ... It's a pity that evince can't read from STDIN ... If you decide to go with the temporary files way, it can be done easily with mktemp like so et=$(mktemp); man -t nano > "$et"; evince "$et" ... However, possibilities are endless and things can get more complicated with functions and scripts. – Raffa Apr 01 '22 at 17:37
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

Jim L.
  • 206
  • 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 Apr 06 '22 at 01: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.

ssokolow
  • 2,238