[英]tail -f OR less +F how to highlight new lines
Is there any way to highlight, ie bold, or colorize new added lines since last change? 自上次更改以来,是否有任何方法可以突出显示(即加粗)或为新添加的行着色?
For example, I am watching a log file with multiple similar errors in PHP error_log (different line or function name, etc)... And I have to look at timestamps where one set of errors ends and another begins (page refresh) 例如,我正在查看一个日志文件,该文件在PHP error_log中有多个类似错误(不同的行或函数名称,等等)...而且我必须查看一组错误结束而另一组错误开始的时间戳(页面刷新)
It would be very helpful if there is a way to highlight, but only last added lines. 如果有一种方法可以突出显示,但只能最后添加几行,那将非常有帮助。
I am looking for solution to run on macOS and Linux in console. 我正在寻找在控制台上的macOS和Linux上运行的解决方案。
Check out the watch
command, if your system has it. 查看
watch
命令(如果您的系统具有该命令)。 The command: 命令:
watch -d tail /your/file/here
will display the file and highlight the differences character by character. 将显示文件并逐字符突出显示差异。 Note that you do not want to use the
-f
option in this case. 请注意,在这种情况下,您不想使用
-f
选项。
Ubuntu has it. Ubuntu拥有它。 For OSX, you can can use
brew install watch
if you have homebrew
installed or sudo ports install watch
if you use ports
. 对于OSX,如果
brew install watch
homebrew
,则可以使用brew install watch
如果使用ports
则可以使用sudo ports install watch
。
Another bonus is that it works for any command that has output that changes over time. 另一个好处是,它适用于输出随时间变化的任何命令。 We have even used it with
ls -l
to watch the progress of backups and file compressions. 我们甚至将它与
ls -l
一起使用,以观察备份和文件压缩的进度。
"tail" itself does not offer a serious way to do this. “尾巴”本身并不提供执行此操作的严肃方法。 But give "multitail" a closer look:
但是,让“ multitail”更近一些:
https://www.vanheusden.com/multitail/ https://www.vanheusden.com/multitail/
And for Mac OSX: 对于Mac OSX:
http://macappstore.org/multitail/ http://macappstore.org/multitail/
Turn on grep
's line buffering mode. 打开
grep
的行缓冲模式。
Using tail 使用尾巴
tail -f fileName | grep --line-buffered my_pattern
Using less 少用
less +F fileName | grep --line-buffered my_pattern
Using watch & tail to highlight new lines 使用手表和尾巴突出新的线条
watch -d tail fileName
Note: For linux based systems.
注意:对于基于linux的系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.