Why does less tail mode stop working?

11

4

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?

TREE

Posted 2009-10-08T13:28:04.420

Reputation: 1 147

FYI, this remains unanswered because the file in question was not being rolled/rotated/recreated. – TREE – 2012-04-26T14:17:09.347

Have you tried using strace to see what it's (not) doing? Maybe you'll see an error. – wfaulk – 2009-10-08T15:39:17.787

Answers

12

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.

Doug Harris

Posted 2009-10-08T13:28:04.420

Reputation: 23 578

+1 perfect answer, that's just why this option was introduced. Note that --follow-name was introduced in less v415 (http://www.greenwoodsoftware.com/less/news.415.html ), released 15 Nov 2007. Thus old Linux installation may not have it.

– sleske – 2011-04-29T08:55:08.637

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).

Randy Orrison

Posted 2009-10-08T13:28:04.420

Reputation: 5 749

If this is the case, try tail --follow=name [filename] (which causes tail to periodically reopen the file in case it is renamed). See http://www.gnu.org/software/coreutils/manual/html_node/tail-invocation.html

– Randy Orrison – 2009-10-08T14:49:35.797

No, the logs are not rotating. It's the same file. – TREE – 2009-10-08T15:14:03.120

1

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

brandstaetter

Posted 2009-10-08T13:28:04.420

Reputation: 4 119

4With 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 – 2009-10-08T15:06:42.930

tail -f does work, but I'd prefer to work within less. – TREE – 2009-10-08T15:14:45.367

I see. Did not know that. – brandstaetter – 2009-10-08T15:22:56.973

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

WesternGun

Posted 2009-10-08T13:28:04.420

Reputation: 300