r/sysadmin • • Mar 30 '15

Linux Stop using tail -f (mostly)

http://www.brianstorti.com/stop-using-tail/
89 Upvotes

23 comments sorted by

44

u/orev Better Admin Mar 30 '15

Less has its uses, but tail -f is far superior because of its simplicity. When I have a tail -f running, I can easily hit enter a few times to create some whitespace between the stuff I already saw and whatever I expect to be new. This makes it trivially easy to see if something was added to the file, especially if I switch to do something else for a while. With less +F, I need to really examine what's on the screen to figure out if anything new was added.

0

u/[deleted] Mar 30 '15

[deleted]

8

u/orev Better Admin Mar 30 '15

I assume you mean "multitail", and it has nothing to do what what I said, not to mention that it's not a standard package on basic server installs.

31

u/[deleted] Mar 31 '15

Stop using tail -f?

Ummm, no.

8

u/radardetector Mar 31 '15

Stop telling me what to do.

3

u/maxgarzo Mar 31 '15 edited Mar 31 '15

Seriously. I'm getting fed up with this type of blogspam. Your workflow is yours, don't tell me what to do with mine. And if you are, at least have a DAMN good reason that you can SHOW me for why I should adopt your methodology.

7

u/jftuga Mar 31 '15

I like this tip and can't wait to try it.

I also like to use:

tail -0f file.log

This starts the 'tail -f' process without seeing any of the previous log entries.

1

u/[deleted] Mar 31 '15

Wow. Today I learned you can tailf multiple logs and only content at the end of a file. Neat. One thing though, it looks like that doesn't work for multiple files unless I'm doing something incorrectly here:

[root@controller ~]# tail -0f  /var/log/httpd/access_log /var/log/messages
tail: invalid option -- 0
Try `tail --help' for more  information.

1

u/jftuga Apr 02 '15

On your version of tail you will have to use -1f instead of -0f. This means you will only see the last line in the log file instead of none.

2

u/[deleted] Apr 02 '15

Hmm, that didn't seem to do it, but the following did:

tail -c 0 -f     
/var/log/httpd/access_log   
/var/log/httpd/error_log

printf "TEST2\nTEST3" >> access_log && printf "TEST2\nTEST3" >> error_log

 ==> /var/log/httpd/access_log       
<==
TEST2
TEST3
==> /var/log/httpd/error_log <==
TEST2
TEST3

10

u/munky9002 Mar 30 '15

It explains what it is. It doesn't explain to me why I should give a shit? 99% of the time when I'm doing tail -f I'm not looking to ever modify the file.

0

u/[deleted] Mar 30 '15

[deleted]

14

u/Drasha1 Mar 31 '15

ctrl + s to pause the terminal and ctrl + q to resume it has always worked fine for me when I needed to pause tail.

6

u/[deleted] Mar 31 '15

...holy shit. I never knew you could do this.

1

u/ender-_ Mar 31 '15

I'm always inside screen, so ^A,Esc, then you can move up and down, and use / to search.

3

u/Fork_the_bomb Mar 31 '15

I'm too entrenched in tail -f, I'll forget this in a sec.

3

u/mrgoalie Jack of All Trades Mar 31 '15

I prefer to use tail -f and pipe what I'm actually looking through grep, so I'm only seeing the bits that I need to see as the logs scroll by

2

u/m0nback Mar 31 '15

"Stop using tail -f" ... because I do it this way. And my way is better.

3

u/A999 Mar 31 '15

less +F doesn't work with ccze, tail does.

1

u/FJCruisin BOFH | CISSP Mar 31 '15

but.. I like tail -f

-3

u/fulanodoe Mar 30 '15

Pretty useful tip.

0

u/[deleted] Mar 31 '15

[deleted]

2

u/[deleted] Mar 31 '15

Yep! That'll show that pesky logrotate process.

4

u/DeathLeopard Mar 31 '15

Nothing better than finding your logging volume full because some idiot habitually leaves disconnected screen sessions running tail -f on logs that should be getting rotated away and deleted. Not that I'd know anything about that.

1

u/[deleted] Mar 31 '15

Some processes rotate quickly, like BIND's own rotating feature. It was awful to try and tail those logs with -f and it turns out the coreutils people already thought of that.

0

u/[deleted] Mar 31 '15

[deleted]

1

u/pahakala Mar 31 '15

yournalctl -fan solves most of my log tailing needs