Live data from Hacker News

Stop using tail -f (mostly)

brianstorti.com

171–180 of 211 posts

Re: Stop using tail -f (mostly)

#171
post #127

Earlier quoted context omitted.

On large files less fires up immediately and vim is quite slow. I think that vim is loading an entire file in the memory while less just loads visible chunk. May be other vi implementations are more efficient with large files. Besides — vim really shouldn't be used on log files. It's editor, not viewer.

Vim ships with a command called `view` that will start it in read-only mode, and makes it very much a viewer — not just an editor.

True, and I like using this for syntax-colored views of files. But it's got an annoying tendency to switch to edit mode with very little fuss.

Sometimes I want a viewer to just be a viewer.

Speaking of which: are there any Linux/Unix viewers that do have generalized syntax highlighting support?

Re: Stop using tail -f (mostly)

#172
post #124
post #16

Earlier quoted context omitted.

+1 (upvoted). $ less ./somefile /somesearch^M ( (Edit: formatting)

But how do you combine the two on the command line, so less is tailing the file AND highlighting a pattern when launched? I typically read logfiles with less +F, but it would be nice to create an alias for patterns in specific types of logs, so I don't have to remember them or rely on command history.

bch has it. Less has ancient command line args, they aren't getopt style.

Re: Stop using tail -f (mostly)

#177
Thanks! This is really great trick. I will obviously use less +F for tailing single file.

Meanwhile, tail -f still useful for simple tailing to multiple machine, like

    function dogfight_tail {
     logfile=/var/log/nginx/access.log
     pids=""
     for box in 02 03; do
       ssh lb$box tail -f $logfile | grep " 500 " & # find error machines
       pids="$pids $!"
     done
     trap 'kill -9 $pids' SIGINT
     trap  wait
    }

    dogfight_tail

Re: Stop using tail -f (mostly)

#180

> We all have been there: You are watching a file with tail -f, and then you need to search for something in this file, or just navigate up and down. Now you need to exit tail (or open a new shell), and ack this file or open it with vim to find what you are looking for. After that, you run tail again to continue watching the file. There's no need to do that when you are using less. There's also no need to do that if…

I see that tmux doesn't come as part of standard ubuntu installation. So I think that puts it at a disadvantage for not being omnipresent.
Post reply on HN