Written by
Jenny ZengThe macOS Terminal app doesn't provide a great experience for reading man (manual) pages. If you're tired of viewing a man page in Terminal or you want to document a man page for future retrieval, you can use the methods laid out in this post.
How to export a man page in Terminal as a plain text file?
There are two ways to export a Terminal man page as a plain text file.
Use the Shell menu: Inside Terminal, click Shell at the menu bar, then select "Export Text As" and choose a desired location to export all texts of a man page from Terminal. If you only want to export selective texts, select them, then click Shell > Export Selected Text As. (This is also helpful for saving commands output in Terminal.)
Run Terminal command: You can also execute a Terminal command to export the man page of a command as a text file.
man command | col -bx > /path/to/command.txt
For instance, if you want to export the ls man page to a new plain text file on your desktop and name it as ls.txt, the command should be: man ls | col -bx > ~/desktop/ls.txt
Spread the information by sharing this post!
How to convert a Terminal man page as a PDF?
If you want to convert a Terminal man page into a PDF file on Mac, you can try the following methods:
① Use the pstopdf command
man -t command | pstopdf -i -o name.pdf
Replace "command" and "name" with the ones you want to use. For example, to convert the ls man page into a PDF and name it ls.pdf, run: man -t ls | pstopdf -i -o ls.pdf. If the command executes successfully, you'll find the ls.pdf file in your home directory (e.g., Macintosh HD/Users/Jenny).
② Convert from .txt to .pdf
You can first save the man page as a text file, as we mentioned in the first section of this post. Then open the text file with TextEdit and click File > Export as PDF to convert it into a PDF file.
③ Copy the content of the man page and paste it to a PDF file
As an alternative, you can copy all texts on a man page to the clipboard and then paste them into a PDF file.
Press Command + C to copy the texts, or execute the command below:
man command | col -b | pbcopy
For example, to copy the contents of the ls man page, run: man ls | col -b | pbcopy
Share this post to help others convert Terminal man pages to PDFs!