Update to man hint

Mark Hymers markh at linuxfromscratch.org
Tue Mar 26 10:44:31 PST 2002


I've updated the man hint with the script for compressing man-pages.
Gerard's agreed that I'll take it over.  I've removed the section on cat
man pages because, basically, it doesn't work.  I'll investigate that
ASAP.  In the meantime, can you commit the new hint.



Mark Hymers					BLFS Editor
markh at linuxfromscratch.org
-------------- next part --------------
TITLE:		The Man Hint
AUTHOR:		Mark Hymers <markh at linuxfromscratch.org>

SYNOPSIS:	Formating and Compression issues for man pages

Note: This hint was previously maintained by 
Rudolf Floers <r.floers at web.de> 
and then by Gerard Beekmans <gerard at linuxfromscratch.org>.  
Thanks to both of them.  Any bugs, however, are still my responsibility!


(1)  Compression of man pages

If you want to save a little diskspace, you can safely bzip2 or gzip all
manpages.   We used to recommend just using gzip /usr/share/man/*/* (or
the bzip2 equivalent) but that breaks symlinks.  Instead, you can use
the following script. 

(a copy is available from
if you want to avoid cutting and pasting it!)

# Compress (with bzip2 or gzip) all man pages in a hierarchy and
# update symlinks - By Marc Heerdink <marc at koelkast.net>.
# Modified to be able to gzip or bzip2 files as an option and to deal
# with all symlinks properly by Mark Hymers <markh at linuxfromscratch.org>
# WARNING: This script still can't cope with hard-links (suggestions are
# welcome on how to deal with this)
# The only time this should be a problem is if you have a symlink to a
# hardlink; but then, you're sick if you do that anyways :-)

if [ ! -d "$1" -o -z "$1" ] || [ "$2" != "bz2" -a "$2" != "gz" ]; then
  echo "Usage: $0 <dir> <bz2/gz>"
  exit 1

for DIR in $1/man*; do
  cd $DIR

  for FILE in *; do

    if [ -L "$FILE" ]; then
        case $FILE in
            EXT=bz2 ;;
            EXT=gz ;;
            EXT=none ;;

        if [ "$EXT" != "none" ]; then
            LINK=`ls -l $FILE |cut -d ">" -f2 |tr -d " " | sed s/.$EXT$//`
            NEWNAME=`echo "$FILE" | sed s/\.$EXT$//`
            mv "$FILE" "$NEWNAME"
            LINK=`ls -l $FILE |cut -d ">" -f2 |tr -d " "`

        rm -f "$FILE" && ln -s "${LINK}.$2" "${FILE}.$2"
        echo "Relinked $FILE"

    elif [ -f "$FILE" ]; then
        case $FILE in
            bunzip2 $FILE
            FILE=`echo $FILE | sed s/\.bz2$//`
            gunzip $FILE
            FILE=`echo $FILE | sed s/\.gz$//`

        case $2 in
            bzip2 "$FILE" && chmod 644 "${FILE}.${2}";;
            gzip "$FILE" && chmod 644 "${FILE}.${2}";;

        echo "Compressed $FILE"


  done # for FILE
done # for DIR

Don't forget to set the script to be executable and then run it using 
something like:
./compman /usr/share/man bz2

The first option is the tree of man pages to compress.
The second options is bz2 or gz; it tells the script which compression
you want to use.

(2)      cat pages

TO BE ADDED - There's a slight problem; I can't get it to work at the
moment.  Hopefully this'll get fixed soon!

More information about the hints mailing list