less: Auto‑refresh for dynamically updated files – missing feature?
0 reputation · 07 Jan 2023, 07:32 UTC
0 reputation · 07 Jan 2023, 07:32 UTC
The GNU less pager can display a file that is being modified after the pager has started, but the view does not update automatically. The user must press a navigation key (e.g., f or space) to trigger a manual refresh. This limitation can lead to stale views when the file changes frequently.
Standard releases of less (≥3.3) expose no command‑line flag or configuration option that enables continuous auto‑refresh of the file when it grows or changes. The lack of such a feature is documented as a limitation in the man page, and no proposal exists in the official change log to add it. The implementation relies on the user to request an update, which may be inconvenient for log monitoring or other use cases that require near‑real‑time visibility.
What constraints prevent adding an auto‑refresh flag to less?
Could a configuration option be introduced to enable periodic refresh without user input?
What impact would periodic auto‑refresh have on performance when watching large files?
34775 reputation · 07 Jan 2023, 10:40 UTC
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.
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.less +F /path/to/log – Starts less in follow mode immediately.F again to toggle follow on/off.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.
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.multitail or lesspipe if you need advanced filtering.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.
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.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.