Answer
GNU less does not provide a generic “auto‑refresh” flag that continuously re‑reads a file when it changes. The only built‑in way to get near‑real‑time updates is the F (follow) command, which behaves like tail ‑f and only shows data appended to the end of the file. It does not handle truncation, file replacement, or log rotation reliably. For rotation‑aware following you should use tail ‑F or a wrapper such as watch.
Why Less Lacks a Periodic Refresh Option
- Less is designed as an interactive pager that waits for user input in its main loop. Adding a timer‑based repaint would require asynchronous I/O handling that the current implementation does not support.
- The
R command is the documented manual refresh: pressing R forces a re‑read of the file. It is intentionally user‑initiated to avoid unnecessary work when the file is static.
- Implementing a periodic refresh would add overhead on large files, especially if line wrapping or syntax highlighting is enabled. The cost is modest for short intervals but can cause flicker and CPU spikes for multi‑gigabyte logs.
How to Use Follow Mode for Growing Logs
less +F /path/to/log – Starts less in follow mode immediately.
- While in less, press
F again to toggle follow on/off.
- Press
R if you want to refresh the view manually after a truncation or rotation.
Note that less +F only displays new lines appended after the pager starts. If the file is truncated or replaced (common with log rotation), less will stop following and may show stale content. In that case, exit less and re‑open it, or use tail ‑F instead.
Alternatives for Rotation‑Aware Watching
tail ‑F /path/to/log | less – Pipes the continuously updated output into less, but the pipe cannot be re‑stat’d, so rotation is still handled by tail ‑F.
watch -n1 cat /path/to/file – Re‑displays the entire file every second; useful for small files that are rewritten entirely.
- Use
multitail or lesspipe if you need advanced filtering.
What You Might Need to Verify
Different less builds (e.g., less 5.95 on Linux vs. less 6.0 on macOS) may handle file truncation slightly differently. If you encounter unexpected behavior, check the version with less --version and consult the man page sections for F and R.
Missing Diagnostic Detail
Could you let us know which operating system and less version you are using? That will help confirm whether the F command behaves as described or if a patch is required.