Live data from Hacker News

Stop using tail -f (mostly)

brianstorti.com

161–170 of 211 posts

Re: Stop using tail -f (mostly)

#161
I think that it's worth noting that you should still use `-f` if you are viewing a file over SSH that is being appended to a ton and you don't need every line. SSH will require that every line makes it to your terminal over it's secure connection, so you will be bottlenecked and most likely won't be viewing the latest messages. Everything will be queued.

Re: Stop using tail -f (mostly)

#164
post #154

Interesting. I always preferred watch -n 1 -d 'tail /path/to/log/file' to tail -f because of its nice highlighting feature.

watch is one of the great unsung heroes of unix tools. Discovering it was one of those "I wish I knew about this years ago" moments. Unfortunately it doesn't seem to have spread much beyond GNU/Linux platforms.

Re: Stop using tail -f (mostly)

#165
Haha I didn't know a lot of people didn't know about this. I am one of those people who likes to read man pages :D Another favorite one of mine is the `v` switch to quickly jump to the editor from `less`. Pretty handy!

Re: Stop using tail -f (mostly)

#166

I was introduced to less +F a while ago and it is quite nice, but there is one simple "feature" of tail -f that I miss quite a lot: being able 'mark' the log with gaps by hitting enter a few times. This is especially handy when you have to first load a page or warm up the app before performing the operation you're interested in watching, letting you separate the earlier output from the lines generated by what you're…

On OSX/iterm you can do command+k to clear the screen and less lets you navigate up if you need.

Re: Stop using tail -f (mostly)

#167

Earlier quoted context omitted.

I think your idea of `vi -R` or `vim -R` is a good idea. `less` uses less memory and may load faster but looking at logs for things like valgrind vim will give you syntax highlighting that I am not sure you can get with `less`.

BTW, starting vim as "view" (through e.g. a symlink) is equivalent to "vim -R", precisely for this use case [0]. [0] http://vimdoc.sourceforge.net/htmldoc/starting.html#view

I have used `view` but it didn't give me syntax highlighting. On my system (archlinux) view is actually a symlink to ex (which must change its behavior based on its name?).

    readlink /usr/bin/view
    ex

Re: Stop using tail -f (mostly)

#168
post #31

Earlier quoted context omitted.

With less, you can use m to mark the current position and ' to go to a marked position. h will show you lots of useful help.

An example of some of the vi commands that less(1) has adopted. You can also: * page forward and backward, including using numeric prefixes to indicate a lineno or indicate "repeat 'n' times". * launch vi if less(1) is working on a file (versus (eg) stdout of some process) * search fwd/backward * start examining a new file w/o leaving less(1) * ...

'&pattern' filtering is huge for me.

Display only lines which match the pattern; lines which do not match the pattern are not displayed. If pattern is empty (if you type & immediately followed by ENTER), any filtering is turned off, and all lines are displayed. While filtering is in effect, an ampersand is displayed at the beginning of the prompt, as a reminder that some lines in the file may be hidden.

Re: Stop using tail -f (mostly)

#169
post #8

This _almost_ touches on the useful part of this: If you search in less and then put it in follow mode, it continues to highlight the search terms. This is very useful for trapping an exception or webcall in the wild. The downside: less buffers and tail -f prints directly. On a slow printing log this can cause events to show up slowly, and can cause performance issues on a fast moving log. If you're piping through a…

I was going to mention multitail as well, which is a fantastic utility. That and rsstail, both by Folkert Van Heusden, are quite slick. The mark it leaves (a red line across the screen) is even more visible than those given by less.

I've commented a bit more on them (in the context of other RSS tools) here:

https://www.reddit.com/r/dredmorbius/comments/1udv6i/further...

Folkert's site: http://www.vanheusden.com/ http://www.vanheusden.com/multitail/ http://www.vanheusden.com/rsstail/

Though not quite applicable to logfiles, I've written a script to tail my Newsbeuter feed URLs with Multitail support, for a console / terminal-based RSS feed.

Post reply on HN