11

Using the less command on linux in tail mode (F command or less -f) consistently stops working on certain machines and/or certain files. New changes simply stop showing up.

I know I've fixed this before, long ago, but I don't recall what the solution was.

Any ideas?

2
  • Have you tried using strace to see what it's (not) doing? Maybe you'll see an error.
    – wfaulk
    Oct 8, 2009 at 15:39
  • FYI, this remains unanswered because the file in question was not being rolled/rotated/recreated.
    – TREE
    Apr 26, 2012 at 14:17

4 Answers 4

13

Try using less --follow-name. Even if the file has the same name, the process(es) updating it may be doing so in a way which changes the file's inode -- so from the OS point of view, it's a new file after the updates.

2
  • 1
    +1 perfect answer, that's just why this option was introduced. Note that --follow-name was introduced in less v415 (greenwoodsoftware.com/less/news.415.html ), released 15 Nov 2007. Thus old Linux installation may not have it.
    – sleske
    Apr 29, 2011 at 8:55
  • This should only be an answer if the file is being rolled/rotated/recreated FWIW...
    – rogerdpack
    Apr 7, 2021 at 17:46
3

Are you viewing log files that are rotated by logrotate? If the file that less is viewing is renamed (e.g. from log to log.0 by logrotate), less will continue to watch that file, even though new entries are being written to a different file (with the original name).

2
1

maybe you could try tail -f [filename] instead?

3
  • 4
    With less, you can "pause your tail" (by using Ctrl-c) to go up to a specific line and resume later (using F). That's why in some cases it is preferred over "tail -f".
    – dogbane
    Oct 8, 2009 at 15:06
  • tail -f does work, but I'd prefer to work within less.
    – TREE
    Oct 8, 2009 at 15:14
  • I see. Did not know that. Oct 8, 2009 at 15:22
0

I do less +F --follow-name. --follow-name just monitors the file with same name without receiving the incoming changes in my case(CentOS 7).

Actually I create an alias for this:

Add this line in /etc/profile.d/alias.sh:

alias lf="less +F --follow-name"

Save, and source it to use it now. . /etc/profile.d/alias.sh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .