1

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.

1 Answer 1

1

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.

3
  • Awesome! I didn't see or understand at first what follow-name actually did. I should have stated in my question that I didn't wanted to launch less with +F since I often want to search for something in the file first and then maybe start tailing the log but adding --follow-name as always being added solves that case as it seems. Thank you!
    – Björn
    Jun 11, 2022 at 8:33
  • Modified answer accordingly.
    – A.B
    Jun 11, 2022 at 9:23
  • Great note about LESS environment variable, thanks!
    – Björn
    Jun 12, 2022 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .