Linux 搜索结果显示为尾操作的数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10350160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:01:46  来源:igfitidea点击:

search with in Data displayed as a result of tail Operation?

linux

提问by user1253847

I am working on a Java EE application where its logs will be generated inside a Linux server .

我正在开发一个 Java EE 应用程序,它的日志将在 Linux 服务器内生成。

I have used the command tail -f -n -10000 MyLogIt displayed last 1000 lines from that log file .

我使用了命令tail -f -n -10000 MyLog它显示了该日志文件的最后 1000 行。

Now I pressed Ctrl + c in Putty to disconnect the logs updation ( as i am feared it may be updated with new requests and I will loose my data )

现在我在 Putty 中按 Ctrl + c 断开日志更新(因为我担心它可能会随着新请求更新,我会丢失我的数据)

In the displayed result, how can I search for a particular keyword ?? (Used / String name to search but it's not working)

在显示的结果中,我如何搜索特定的关键字??(使用/字符串名称进行搜索但它不起作用)

回答by tuxuday

Pipe your output to PAGER.

将您的输出通过管道传送到 PAGER。

tail -f -n LINE_CNT LOG_FILE | less

then you can use

然后你可以使用

/SEARCH_STRING

回答by Attila

You need to redirect the output from tailinto a search utility (e.g. grep). You could do this in two steps: save the output to a file, then search in the file; or in one go: pipe the ouput to the search utility

您需要将输出重定向tail到搜索实用程序(例如grep)。您可以分两步执行此操作:将输出保存到文件,然后在文件中搜索;或者一次性:将输出通过管道传输到搜索实用程序

To see what goes into the file (so you can hit Ctlr+c) you can use the teecommand, which duplicates the output to the screen and to a file:

要查看文件中的内容(以便您可以按 Ctlr+c),您可以使用该tee命令,它将输出复制到屏幕和文件中:

tail -f -n -10000 MyLog | tee <filename>

Then search within the file.

然后在文件中搜索。

If you want to pipe the result into the search utility, you can use the same trick as above, but use your search program instead of tee

如果要将结果通过管道传送到搜索实用程序,可以使用与上述相同的技巧,但使用搜索程序而不是 tee

回答by dwurf

Two ways:

两种方式:

tail -n 10000 MyLog| grep -i "search phrase"

tail -f -n 10000 MyLog | less

The 2nd method will allow you to search with /. It will only search down but you can press g to go back to the top.

第二种方法将允许您使用 / 进行搜索。它只会向下搜索,但您可以按 g 返回顶部。

Edit:On testing it seems method 2 doesn't work all that well... if you hit the end of the file it will freeze till you ctrl+c the tail command.

编辑:在测试中,似乎方法 2 不能很好地工作......如果你点击文件的末尾,它会冻结,直到你 ctrl+c 尾命令。

回答by Rob Kielty

Controlling terminal output on the fly

即时控制终端输出

While running any command in a terminal such as Putty you can use CTRL-Sand CTRL-Qto stop and start output to the Putty terminal.

在终端(例如 Putty)中运行任何命令时,您可以使用CTRL-SCTRL-Q来停止和启动到 Putty 终端的输出。

Excluding lines using grep

使用 grep 排除行

If you want to exclude lines that contain a specific pattern use grep -vthe following would remove all line that contain the string INFO

如果要排除包含特定模式的行,请使用grep -v以下将删除所有包含字符串 INFO 的行

tail -f logfile | grep -v INFO 

Show lines that do not contain the words INFO or DEBUG

显示不包含 INFO 或 DEBUG 字样的行

tail -f logfile | grep -v -E 'INFO|DEBUG'

Finally, the MOTHER AND FATHER of all tailing tools is xtail.pl

最后,所有尾随工具的母亲和父亲是xtail.pl

If you have perl on your host xtail.pl is a very nice tool to learn and in a nutshell you can use it to tail multiplefiles. Very handy.

如果您的主机上有 perl,那么 xtail.pl 是一个非常好的学习工具,简而言之,您可以使用它来跟踪多个文件。非常便利。

回答by Nten0

You can just open it with less command

你可以用更少的命令打开它

less logfile_name

when you open the file you can use this guide here

当您打开文件时,您可以在此处使用本指南

Tip: I suggest, first to use G to go to the end of the file and then to you use Backward Search

提示:我建议,首先使用 G 到文件末尾,然后使用向后搜索