Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 8 down vote accepted

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.
share|improve this answer
    
Why does -F only work with -X? –  Jesse Sep 2 '13 at 5:50
    
@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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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