1

Running less +F file is very convenient because you can switch in and out of forward-forever mode with Ctrl-C and -F respectively.

Unfortunately new lines appear with a delay, which is very irritating when you are watching and comparing with something else.

tail -f does not have this delay, but you can't easily switch out of forward-forever mode to scroll up or search or something.

Is there a way to combine the best of both?

3

The reason you're experiencing a delay when using less +F is this (taken from this answer, which is so good I'll quote it verbatim):

less +F reads the whole file, whereas on many systems tail -f only reads the end of the file, and even on the systems where it does read the whole file, at least it doesn't keep the whole file in memory. That makes less +F impractical for very large files. You can however run less -n +F, which causes less to read only the end of the file, at the cost of not displaying number.

Under the hood, between less -n +F and tail -f does, the main difference is that tail uses a file change notification service on some platforms (e.g. inotify on Linux), which allows it to display new data instantly, whereas less might take up to 1 second to display the new data because it checks for new data in a loop and sleeps between checks.

  • Thanks, I assumed you could just block on a read and you would be scheduled when new data arrives, but apparently you need a file system event. With this knowledge I looked up the code in tail and sent an email to Mark Nudelman. – AndreKR Nov 10 '17 at 11:09

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.