Linux - some way to keep a live-updating log file open in terminal?

48

18

This must've been done before: I want to keep a log file open in terminal so I can monitor updates to it as they occur. My searches are coming up with everything but this situation... I must be missing some terminology or something key, because people do this all the time inside of other programs (NetBeans, or rails server, for example).

wulftone

Posted 2011-05-20T19:19:09.403

Reputation: 823

4Ah, I've found it. tail -f myfile.log. That does it nicely. I love linux. – wulftone – 2011-05-20T19:23:51.057

Answers

84

Try with:

tail -f your.log

where -f stands for follow.

cYrus

Posted 2011-05-20T19:19:09.403

Reputation: 18 102

As you may need syntax highlight, multitail is handy i.e. multitail -f your.log ref. http://unix.stackexchange.com/a/8419/17671

– Nam G VU – 2016-09-22T04:45:48.657

Or even better is grc i.e. grc tail -f your.log ref. http://unix.stackexchange.com/a/21962/17671

– Nam G VU – 2016-09-22T04:48:47.917

10

Another way:

watch tail -n20 your.log

OK, kind of a silly use of watch - but you might find the watch command useful for other things.

Robin Green

Posted 2011-05-20T19:19:09.403

Reputation: 1 107

5The watch option is better for files that are going to be renamed/removed and recreated (either by normal operation or by something like logrotate) during the time you are watching, otherwise tail -f is more efficient. – David Spillett – 2011-05-20T20:07:57.633

6@David: tail -F handles that. – user1686 – 2011-05-21T10:11:04.143

@grawity: Thanks, you learn something new every day! – David Spillett – 2011-05-21T11:25:22.463

3

An alternative to @cYrus's answer is:

less +F file.log

The benefit is that less can also truncate long lines for you with the -S flag, preventing them from wrapping around the terminal screen while allowing you to scroll left/right. Instead of piping tail -f file.log through cut or something similar, you can just:

less -S +F file.log

Severyn Kozak

Posted 2011-05-20T19:19:09.403

Reputation: 135