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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can less follow (by pressing F) a piped input (similarly to a file)? For a file that is being written to, the command

less <file>

will follow the file when pressing F.

But if I have a command that pipes output directly into less, like this

command | less

pressing F will do nothing.

So it looks like pipes cannot be followed like files can? Or maybe it has to do with command also writing to STDERR? The effect I'm trying to achieve is always see the latest output of the command: just like keeping PageDown pressed!

A related remark holds for G (go to end): when piping directly to less, it won't work.

share|improve this question
    
up vote 10 down vote accepted

Pressing F or G makes less try to reach input EOF. If the input is a pipe, less hangs until the pipe is closed on the other side (and not "does nothing").

This can be worked around by saving the command output to a temporary file in the background, and then by using it as input for less:

command > /tmp/x &
less +F /tmp/x; kill %; rm /tmp/x

There is no option to do this in less only; however, I admit it would be useful.

share|improve this answer
    
If the input is a pipe, less hangs until the pipe is closed on the other side. That's kind of misleading statement. What happens is that less calls read in a blocking mode, waiting for new data or or pipe's closure. – Piotr Dobrogost Dec 11 '14 at 11:24
1  
After pressing F or G on pipe input less not only does a blocking read, but does it in a loop waiting for EOF. And an EOF on a pipe happens only if its other side is closed. – mik Feb 12 '15 at 22:29
1  
If less would update screen in that loop, there would not be a problem. Blocking read has little to do with this issue. – mik Feb 12 '15 at 22:46
    
If the input is a pipe, less hangs until the pipe is closed on the other side. That's not my observation. For example echo foo |less +F results in less displaying Waiting for data... (interrupt to abort), so it does not hang until the pipe is closed, but until an interrupt is received. – Flow Jun 23 at 12:03
    
@Flow this is not a hang the question was about, but merely a wait which is expected in this situation - a wait for more data in the file when EOF is reached (which will not happen for a closed pipe, by the way), or for an interrupt to exit the follow mode – mik 9 hours ago

Can less follow (by pressing F) a piped input (similarly to a file)?

Currently not but this issue is on the official list of bugs with reference number 300:

The F command does not work on piped input.


A related remark holds for G (go to end): when piping directly to less, it won't work.

It works starting from version 466. Citing from release notes for this version:

New command ESC-G goes to end of currently buffered data in a pipe

share|improve this answer
    
The ESC-G command was introduced in version 466, released on 23 Aug 2014. – mik Feb 12 '15 at 23:02
    
@mik Looks like an error in release notes for version 471 then. Thanks, fixed. – Piotr Dobrogost Feb 12 '15 at 23:11
    
Not an error, they just list the changes incrementally since a stable release, version 458 in this case. However, there is no stable release with the ESC-G command. – mik Feb 12 '15 at 23:56
    
The ESC-G command is now in a stable release (481): "16 Oct 2015 less-481 has been released for general use". – mik Feb 18 at 16:41

From the less man page

[Keyboard] COMMANDS [...]

   F      Scroll  forward, and keep trying to read when the end of file is reached.  Normally this command would be used when already
          at the end of the file.  It is a way to monitor the tail of a file which is growing while it is being viewed.  (The  behav‐
          ior is similar to the "tail -f" command.)

so this should work, and it actually works for me.

share|improve this answer
    
This command behaves differently when used with pipe as described by @mik and is clearly not what OP is looking for. – Piotr Dobrogost Jan 29 '15 at 15:41

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.