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.
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-nameis specified, during an
Fcommand 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).
By the way
--follow-name is not specifically about symbolic links, but it applies to a replaced symbolic link pointing to a different file.