17

When more is passed a file whose contents can be displayed on one screen, it just writes the file's contents to stdout without pagination. If the file cannot fit on one screen, more paginates it.

less has an option to quit if the file it is working with can be displayed on one screen (-F) and it has a more-emulation feature that behaves in a similar manner to the -F flag, but neither of these options seems to cause less to write the file's contents to stdout if the contents can fit on one screen.

How can I get less to write a file's contents to stdout if the file's contents can fit on one screen and paginate the file as it normally would otherwise?

1 Answers1

20

Use less -FX. From man less:

   -F or --quit-if-one-screen
          Causes less to automatically exit if the entire file can be dis-
          played on the first screen.

   -X or --no-init
          Disables sending the termcap initialization and deinitialization
          strings  to  the  terminal.   This is sometimes desirable if the
          deinitialization string does something unnecessary, like  clear-
          ing the screen.
Chris Down
  • 125,559
  • 25
  • 270
  • 266
  • Why does -F only work with -X? – Jesse Sep 02 '13 at 05:50
  • 3
    @Jesse It actually works fine without -X, just not as you expect. Since less is a pager that acts on the alternate screen in your terminal, if you don't disable the termcap initialisation, it will both start and quit on the alternate screen. You'll probably see a quick flash. – Chris Down Sep 02 '13 at 08:30
  • So I don't see anything with echo lol | LESS=F less because it prints on an alternate screen and immediately switches back? Makes sense I guess (although I don't see a quick flash). Thanks. – Jesse Sep 03 '13 at 00:01
  • Bah! I wonder what the hell the less developers thought when using the alternate screen if -F is present and "used". It makes no sense at all to use the alternate screen in this case. – ThiefMaster Dec 25 '13 at 17:31
  • 1
    See http://unix.stackexchange.com/q/107315/85237 for making less -F work without -X. – John Mellor May 23 '15 at 19:07