r/sysadmin • u/speckz • Mar 30 '15
Linux Stop using tail -f (mostly)
http://www.brianstorti.com/stop-using-tail/31
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.logThis starts the 'tail -f' process without seeing any of the previous log entries.
1
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
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
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
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
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
3
1
-3
0
Mar 31 '15
[deleted]
2
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
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
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.