【问题标题】:Grep in screen not saving output to logfile屏幕中的 Grep 未将输出保存到日志文件
【发布时间】:2017-11-16 18:01:57
【问题描述】:
我正在尝试对我的文件执行很长的 grep 扫描。因为屏幕会在执行后关闭,所以我正在尝试写入日志文件以保存 grep 的输出。出现如下命令:
screen fgrep "needle" /mnt/Volume_volume/haystack/* >> /mnt/Volume_volume/log.txt
很遗憾,日志文件是空的。什么地方出了错?屏幕的输出是否被保存而不是 grep?我该如何解决这个问题?
【问题讨论】:
标签:
linux
bash
grep
gnu-screen
【解决方案1】:
你写的命令意思是:运行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 &
也适合你。