linux man2html script

在linux中,可以利用系统提供的man2html命令,将linux命令的man手册转成html代码,将下面的源码保存为man2html.sh,这个脚本可以将man批量转化成html代码

#!/bin/bashif [ $# -eq 0 ]then    echo "Usage: ./man2html.sh /path/to/man/dirctory /path/to/html/output/dirctory"    echo "Exampe: ./man2html.sh /usr/share/man/man1 /tmp/html1"fidir=/usr/share/man/man1output=/tmp/html1if [ $# -eq 1 ]then    dir=$1elif [ $# -eq 2 ]then    dir=$1    output=$2fiecho "./man2html.sh ${dir} ${output}"if [ ! -d $output ]then    mkdir -p $outputfiif [ -d $dir ]then    mkdir -p /tmp/unzipped    cd $dir    for f in *.gz; do        if [ -f $f ]        then            filename=$(basename "${f}" .gz)            unzipfile="/tmp/unzipped/${filename}"            outputfilename="${output}/${filename}.html"            gunzip -c "${f}" > ${unzipfile}            man2html ${unzipfile} > ${outputfilename}            sed -i 's#^Content-type: text/html$##' ${outputfilename}            sed -i 's#</HEAD>#<META charset="UTF-8"></HEAD>#' ${outputfilename}        fi    donefiecho "done!"

man后面的数字说明

  1. User Commands
  2. System Calls
  3. C Library Functions
  4. Devices and Special Files
  5. File Formats and Conventions
  6. Games et. Al.
  7. Miscellanea
  8. System Administration tools and Deamons

man使用

 man -k '^printf' man 1 printf man 3 printf man -a printf

References

  1. What do the numbers in a man page mean