Limiting the width of Linux man command output
Quite often, we need to print the output of the man command. One way is to redirect the man command output to a file, open the file in LibreOffice Writer and export to PDF. The PDF can, later, be printed. However, by default, the man command output comprises of long lines which look great on computer's display but wrap over to next line when printed. One way is to manually format the text in LibreOffice Writer. But this is tedious. How to reduce the width of man command output? If the man command output could be limited to, say, 80 columns, then the text would not wrap over to next line in LibreOffice Writer and the man command output file could be exported to the PDF straightaway.
The solution lies in setting the environment variable MANWIDTH. For example, the following commands need to be given from the shell.
$ export MANWIDTH=80
$ man command > command.txt
Here, command is a Linux command like ls. The width of the output text is limited to MANWIDTH, which is 80 characters in this case. After this the file command.txt can be opened in LibreOffice Writer. You can add page number to pages by, first, click, Insert -> Footer -> Default. And, then, click inside the footer and select center or right justification of text in the footer. Finally, click, Insert -> Fields -> Page Number. Lastly, export the file to the PDF by clicking, File -> Export as PDF.
