Search code examples
linuxgrepfeedtailless-unix

Linux tail + grep + less


I want to see live output from my website's access log. I want to see only certail types of entries, in this case, entries that match ".php".

This works fine, but lines wrap to the next line and I don't want that:

tail -f access-log | fgrep ".php" --line-buffered

This works fine for avoiding the line wrapping, but it is not filtered:

less +F -S access-log

I prefer looking at the file without lines wrapping to the next line because it is easier to see the structure in the output, this is what I want less -S for.

This kind of works, but the "cursor" doesn't stay at the bottom of the file, and any command I enter makes less hang (press "SHIFT + f" for staying at the bottom as the stream comes):

tail -f access-log | fgrep ".php" --line-buffered | less -S

But this doesn't work at all:

tail -f access-log | fgrep ".php" --line-buffered | less +F -S

So, is there a way to achieve the what I want?

I also take outside-the-box solutions, maybe cutting with sed so that each line is never longer than my screen?


Solution

  • With bash I suggest:

    tail -f access-log | fgrep ".php" --line-buffered | cut -c 1-$COLUMNS