Friday, 15 February 2013

How to display percentages in man pages

On many GNU/Linux distributions, man pages are displayed through the "less" pager. I was finding that it was not displaying percentages in man pages. This was due to the fact that the less process was reading its input through a pipe and did not have the whole file loaded.

There is a simple fix (which nonetheless took me a long time to find). Set "LESS=+p" as an environment variable. Then the "p" command will be executed whenever less starts up, which has the effect of loading the whole file. This command is to go to a position in the file marked by a certain percentage, so the whole file must be loaded to know where this is. We are going to 0% in the file, so loading the whole file shouldn't be necessary (as we are not moving anywhere), but less does this anyway.

Obviously, this should be unset if you are doing something like viewing the output of a process through less.

No comments:

Post a Comment