Does “less” have a feature like “tail –follow=name” (“-F”)

The command less can be used to replace tail in

tail -f file

to provide features like handling binary output and navigating the scrollback:

less +F file

The + prefix means “pretend I type that after startup”, and the key F starts following.

But can less also replace

tail --follow=name file

which follows file even if the actual file gets deleted or moved away, like a log file that is moved to file.log.1, and then a new file is created with the same name as the followed file?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Yes, less can follow by file name

The feature has a fairly obscure syntax:

less --follow-name +F file.log

With less, --follow-name is different from the tail option --follow=name.
It does not make less follow the file, instead it modifies the behaviour of the command key F inside of less to follow based on the file name, not the file descriptor.

Also, there is no normal option to start less in follow mode.
But you can use the command line to give keystrokes to execute after startup, by prefixing them with +.
Combining the modifier option with +F, less will actually start in the (modified) follow mode.

Use +F alone for the equivalent of plain tail -f:

less +F file.log

Method 2

In Fedora at least less has a +F option that follows the contents of a file just like tail -f does..

Update, try hitting F in less to toggle to follow mode as well

Method 3

Also you can activate the follow mode if you call less filename like normal and then press Shift + F. With Ctrl + C you can then deactivate follow mode again.

But be aware that by default this will not work in an alpine docker image.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x