How To Find Longest Man Page In Linux

3 Responses

  1. Jalal says:

    Hi,
    Thanks a lot

  2. Sven says:

    #!/usr/bin/env bash
    find -L /usr/share/man/man[1-8] -maxdepth 1 -type f -ls|sort -nk7|tail -80|sed -E ‘s,.*(/usr/share/man/man)([0-9])/([[:graph:]]+).*,printf “%9d\t%d\t%s\n” $(man “\1\2/\3″|wc -l) \2 “\3”,’|bash 2>/dev/null|sort -n

    I knew it was ffmpeg-all before I even read the article or rather did I suspect that it had to be very high up in the top. It then also depends on what you have installed of course. When you don’t have ffmpeg installed then you won’t find it to have the longest manpage…

    Seeing your script, I’d like to note a couple of things about it.

    1. Don’t write fn=${fn#./} but write fn=${fn##*/} While your substitution works is the later better, because the later works universally as a replacement for getting a file’s basename and is much more worth remembering, because it will come in handy many times in future shell scripts. What here works, too, is to the -printf option to find. Using -printf “%f\n” will give you the basename.

    2. When you use ls (or find) then never forget that many distros use synbolic links in quite a few places. Use find and ls with the -L option when you know you do not want to deal with these symbolic links themselves.

    3. Avoid using sed for too many replacements. Firstly, only use sed -E when you actually do use extended regular expressions, which you are not doing here. As you then assign the output to a variable can you use bash’s own builtin substitutions (see the BASH manual on ${VARNAME/pattern/replacement} for this), or since you echo the filename anyway, could you just prepend the path with the echo statement itself.

    4. Using loops in shell scripts can be slow and a faster way can be xargs for example. Try to pipe the output into xargs or a subshell and get it done in one line.

    You can then do it all in one line:

    find -L /usr/share/man/man[1-8] -maxdepth 1 -type f -ls|sort -nk7|tail -80|sed -E ‘s,.*(/usr/share/man/man)([0-9])/([[:graph:]]+).*,printf “%9d\t%d\t%s\n” $(man “\1\2/\3″|wc -l) \2 “\3”,’|bash 2>/dev/null|sort -n

    The one-liner will give you more large manpages and not only the Top-10 of each section. You will see that section 1 of the manpages holds far more large ones and that some sections many not even show up in a Top-100, because these only hold rather small manpages.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.