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?


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.
  • Why does -F only work with -X? – Jesse Sep 2 '13 at 5:50
  • 2
    @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 2 '13 at 8: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 3 '13 at 0: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
  • See unix.stackexchange.com/q/107315/85237 for making less -F work without -X. – John Mellor May 23 '15 at 19:07

Your Answer

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