How to make less +F follow symbolic link if link changes

When you tail a file that is a symbolic link you can make tail follow the link if it changes with tail -F.

Is there someone that have a solution to make less behave the same way if you’re opening a symbolic link in less and press Fand while following the symbolink link it is changed to point to another file?

Edit: I’m aware of launching less with +F but often wante to launch less without +F since to search for something and later on maybe start tailing the log.

Asked By: Björn

||

from less manpage:

--follow-name

Normally, if the input file is renamed while an F command is
executing, less will continue to display the contents of the original
file despite its name change. If --follow-name is specified, during an
F command less will periodically attempt to reopen the file by name.
If the reopen succeeds and the file is a different file from the
original (which means that a new file has been created with the same
name as the original (now renamed) file), less will display the
contents of that new file.

So depending on use case one can use less --follow-name (and type an uppercase F when the need arises) or use less --follow-name +F (to have the F behavior immediately).

This option could also be put for example in the LESS environment variable to avoid having to type it each time.


By the way --follow-name is not specifically about symbolic links, but it applies to a replaced symbolic link pointing to a different file.

Answered By: A.B
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.