2

I recently switched from Ubuntu 15.04 to 15.10 and although they seem to have the same version of less, 458, I get different behavior.

In my new system, if a file has fewer lines than the terminal then less shows it in the bottom of the terminal window, like this:

                          <-
                          <- empty space, not part of file
                          <-
file starts here
  ...
last line of the file
(END) <- symbol inserted by LESS

In my experience with other systems I would get the following behavior instead:

file starts here
  ...
last line of the file
(END) <- symbol inserted by LESS
                          <-
                          <- empty space
                          <-

This is a minor issue but nonetheless important. The problem with the new behavior is that I can't tell from the output whether the file actually starts with empty lines or it's just the way less outputs it because it's too short for the terminal window.

  • which terminal emulation are you using? try "echo $TERM". if using "xterm", this should work as you want. (export TERM=xterm) – gerhard d. Jan 14 '16 at 10:43
  • I'm using xterm-256color. The export did not work but the accepted answer solves the problem. – nedim Jan 14 '16 at 11:04
4

The -c option will force less to start from the top of the screen. You can apply it by default by adding it to the LESS environment variable:

LESS="${LESS:+$LESS }-c"
export LESS

This will take whatever is currently in LESS, if anything, and add -c to it, with a space if necessary.

  • Why ${VAR+...} and not the more canonical ${VAR:+...}? – Otheus Jan 14 '16 at 12:23
  • @Otheus I'm not sure what you mean by "more canonical", but :+ is indeed more appropriate in this case, thanks! – Stephen Kitt Jan 14 '16 at 12:30
  • re "Canonical", strike that. I've simply never seen it before. I think this is like the 4th time one of your answers has positively stunned me. – Otheus Jan 14 '16 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.