Category: Linux Terminal
Added: 9th of July 2022
Viewed: 1,048 times
Related Tips & Tutorials
➔ How to access linux man pages and output specific manual page to a .txt file
Export man pages in .html or .pdf format by installing mandoc on Ubuntu and Ubuntu based distributions
To access the man page for a specific linux command or application, you would enter the following command in the terminal. In the example below I am requesting the manual page for the ls command
The manual page is then displayed in the terminal window.
On Ubuntu and Ubuntu based distributions, man pages (Manual pages) are located in the following directory.
You might like a permanent copy of a man page for reference at later stage. You can copy and paste the information directly to a text file from the terminal, but it will be unformatted.
Another alternative is to install the mandoc package, which has a function to export the man page in .html or .pdf format.
To install mandoc enter the following command in the terminal
sudo apt-get install mandoc
Once installed issue the following command to export the ls man page in .html format
mandoc -Thtml /usr/share/man/man1/ls.1.gz > ls.html
Or issue the following command to export the ls man page .pdf format
mandoc -Tpdf /usr/share/man/man1/ls.1.gz > ls.pdf
Instead of entering the command each time, I put together a small bash script
that searches the man doc directory and then exports the man page in .html and .pdf formats.
Create a folder and file on your desktop using the following commands.
Replace username with your own username
Copy and paste the code below, and save in the manhtmlpdf.sh file you created above.
echo "*** Create HTML/PDF copy of man document ***"
echo "What man page are you looking for?"
if [ -f "/usr/share/man/man1/$manpage.1.gz" ]
echo "Creating $manpage.html and $manpage.pdf files"
mandoc -Thtml /usr/share/man/man1/$manpage.1.gz > $manpage.html
mandoc -Tpdf /usr/share/man/man1/$manpage.1.gz > $manpage.pdf
echo "The man page for $manpage was not found"
Make the file executable by entering the following command in the terminal
chmod +x manhtmlpdf.sh
Run the script by entering the following command