如何压缩/重定向grep后台错误?

时间:2022-12-14 19:36:45

I run grep searches often but sometimes it takes so long I write to a file instead as a background task but it still has output for apparently errors (I think). For example:

我经常运行grep搜索,但有时需要很长时间才能写入文件而不是后台任务,但它仍然有明显错误的输出(我认为)。例如:

grep -rl word . > grep-word.txt &

So this runs it in the background and lets me input new commands while it's running but then it randomly pops up messages like this:

所以这在后台运行它让我在运行时输入新命令,然后随机弹出这样的消息:

grep: ./var/run/dbus/system_bus_socket: No such device or address

How do I get it to suppress or redirect these errors?

如何让它抑制或重定向这些错误?

1 个解决方案

#1


1  

Assuming bash or sh (you don't say what shell you're calling this from):

假设bash或sh(你没有说你从哪个shell调用它):

grep -rl word . > grep-word.txt 2> /dev/null &

#1


1  

Assuming bash or sh (you don't say what shell you're calling this from):

假设bash或sh(你没有说你从哪个shell调用它):

grep -rl word . > grep-word.txt 2> /dev/null &