Raw Control Characters In Less pager

Less is my default terminal pager program. On GNU Debian Linux pager is just a symbolic link to your less or one of other available pager progams like more , most , lv etc..( run update-alternatives —list pager to find out alternative pager programs available on your computer). Lately some funny characters started showing up in my pager .

$ ls /tmp/Foo/ | pager


Oops, That looks like the ANSI Escape Sequences commonly used for making a shell colourful, but our pager program less seems to have some trouble with it. Let’s try to correct this but using -R option which toggles this behaviour.

$ ls /tmp/Foo/ | pager -R

Ok, that seems to fix it. Now let’s set it into our shell environment.You set the same using lesskey also.

LESS=”-R”; export LESS

Please note that using -r option may cause display problems , that’s why I use -R .

Wolfgang Friebel notes in Displaying more with less that ..

Syntax highlighting is only activated if the environment variable LESS is existing and contains the option -R or -r or less is called with one of these options. This guarantees, that instead of literal escape sequences colors are displayed. The detection of the -r/-R presence at runtime is rather dependent on the operating system and may not work in all cases. Putting the option in the LESS environment variable is guaranteed to work.By installing the perl module Proc::ProcessTable the OS dependence can be reduced as well.

1 comment:

  1. For anyone else finding this, if you get an error: "There is no - option ("less --help" for help)" from using the above assignment and export of the LESS variable it is because the quotes around the "-R" are funky.

    Switch to either:
    LESS="-R"; export less;
    LESS=-R; export less;

    either works for me.


You can leave a comment here using your Google account, OpenID or as an anonymous user.