Linux command line log viewer which allows auto tail AND searching?

18

6

I use tail -f in my Linux shell, to view log files, as I like how it auto-updates with the incoming text: I like to see the new stuff come scrolling in.

However, I also like the search functionality of less, which isn't available in tail (or is it?). Is there a "best of both worlds" solution?

If there was a mode I could switch on in less which would make it auto-update with incoming text, then that might be ideal.

Max Williams

Posted 2015-04-16T10:45:03.163

Reputation: 2 237

Does it have to be a simple command or would you accept using a Node.JS command line application? – Julian Knight – 2015-04-16T11:16:18.180

Answers

23

You can run less +F filename in order to view file in tail -f fashion.

You can press Shift+F while viewing file in less to switch to forwarding mode, and Ctrl+C to leave this mode.

Nikolai

Posted 2015-04-16T10:45:03.163

Reputation: 520

Or Shift-End for continuous update. – auxsvr – 2015-04-16T22:35:19.297

5

From less -help:

F Forward forever; like "tail -f".

so presumably less +F /var/log/messages

linuxdev2013

Posted 2015-04-16T10:45:03.163

Reputation: 1 051

You can also press Shift+F while viewing file in less to switch to forwarding mode, and Ctrl+C to leave this mode. – Nikolai – 2015-04-16T12:20:51.233

@linuxdev2013 - starting it with "less -F <file>" doesn't work for me. @Nikolai - shift&f is perfect, thanks! If you want to make that an answer i'll mark it as correct. (btw, in case anyone else is reading, to get out of forwarding mode, it's ctrl&c, or whatever your regular cancel/interrupt keycode is. – Max Williams – 2015-04-16T12:55:36.447

3

Nicolai's answer is probably closest to what you asked for, but have you thought about using tmux?

In my tmux sessions, I like to tail -f logs, then simply enter tmux's copy mode to search up and down exactly like searching in less, then exit copy mode to find my tail -f still going.

Create a tmux session:

tmux

Tail the log file and the last 1000 lines to start:

tail -f -n1000 /var/log/syslog

Enter copy mode using the leader key and a left bracket:

[ctrl+leader] + [

the default tmux leader key is the letter b, so for example:

[ctrl+b] [

Now you can scroll and search up and down just like in less.

Exit copy mode to return to your tail -f with:

[crtl+c]

Bonus material: Open a second terminal prompt:

[ctrl+leader] + c

Switch between the two terminal prompts:

[ctrl+leader] + l

revacuate

Posted 2015-04-16T10:45:03.163

Reputation: 131

0

You could just do

tailf logname.log | grep "query-here"

blakepeterman

Posted 2015-04-16T10:45:03.163

Reputation: 11