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?
Best Answer
Yes,
less
can follow by file nameThe feature has a fairly obscure syntax:
With less,
--follow-name
is different from thetail
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 plaintail -f
: