Grep in screen 不将输出保存到日志文件

Grep in screen not saving output to logfile

我正在尝试对我的文件执行很长的 grep 扫描。因为屏幕会在执行后关闭,所以我试图写入日志文件以保存 grep 的输出。出现以下命令:

 screen fgrep "needle" /mnt/Volume_volume/haystack/* >> /mnt/Volume_volume/log.txt

很遗憾,日志文件为空。什么地方出了错?屏幕的输出是否被保存而不是 grep?我该如何解决这个问题?

您编写的命令表示:运行 screen fgrep "needle" /mnt/Volume_volume/haystack/* 并将此命令的结果附加到文件 /mnt/Volume_volume/log.txt。屏幕会在其输出中显示注释,这就是您在日志文件中得到的内容。

如果你真的想使用屏幕,正确的命令应该是这样的:

screen bash -c 'fgrep "needle" /mnt/Volume_volume/haystack/* >> /mnt/Volume_volume/log.txt'

但我怀疑很简单:

nohup fgrep "needle" /mnt/Volume_volume/haystack/* >> /mnt/Volume_volume/log.txt &

也适合你。