6
1
In less
is there a command for reloading a file from disk, so that less will show any changes made to a file since less was started? This would saving me have to terminate and restart less
if I want to see changes to the file I'm viewing.
6
1
In less
is there a command for reloading a file from disk, so that less will show any changes made to a file since less was started? This would saving me have to terminate and restart less
if I want to see changes to the file I'm viewing.
7
There are two possibly relevant commands detailed in the fine manual for less(1)
R Repaint the screen, discarding any buffered input. Useful if
the file is changing while it is being viewed.
F Scroll forward, and keep trying to read when the end of file is
reached. Normally this command would be used when already at
the end of the file. It is a way to monitor the tail of a file
which is growing while it is being viewed. (The behavior is
similar to the "tail -f" command.)
2
R
for repaint does not always reload the file.[1]
A workaround that always reloads the file is to press hq
, which will open the Help page, then quit. It has a side effect of forcing the file to reload.
[1] Here are some examples of situations that R
do and do not reload:
>
and >>
changes: DO get reloadedsed -i
, gEdit, TextEdit: DO NOT get reloadedvi
changes: DO get reloadedvi
changes: DO NOT get reloadedI believe the difference comes down to whether the inode changes (you can check with ls -i foo.txt
). If the inode changes, then R
will not work.
works for me on Mac. less --version
gives less 487 (POSIX regular expressions)
– john sullivan – 2019-04-17T15:30:02.397
1@johnsullivan Thanks for the comment. I revisited my answer and found that it depends on the situation. When using vi
to edit on Mac, R
doesn't work. But vi
on Linux does. See my revised answer for more details. – wisbucky – 2019-04-17T19:11:37.557
So you mean instead of following data appended to a file using something like
tail -f -n 200 some_file.txt
you would wantless
to reload the file but only show changed content that could be anywhere in the file? Beginning middle or end? – JakeGould – 2017-07-21T15:23:16.400