在 Linux 中,您如何在后台执行命令 运行 而不输出到屏幕?

In Linux how do you make a command run in the background without it outputting to the screen?

我知道乍一看这听起来像是一个愚蠢的问题,但我已经尝试了所有方法。 我想在 Kali Linux 终端中执行命令 arpspoof 但我不想看到无穷无尽的输出。

我先试试这个:

arpspoof -t 10.1.1.1 10.1.1.2 >/dev/null

它仍然输出到屏幕。 然后我试试这个:

arpspoof -t 10.1.1.1 10.1.1.2 & >/dev/null

它仍然输出到屏幕。 然后我在最后添加另一个:

arpspoof -t 10.1.1.1 10.1.1.2 & >/dev/null &

它仍然输出到该死的屏幕。

尝试

arpspoof -t 10.1.1.1 10.1.1.2 2>/dev/null 1>/dev/null &

其中:

arpspoof -t 10.1.1.1 10.1.1.2是你的命令

2>/dev/null 将标准错误 (STDERR) 重定向到 "bit bucket"

1>/dev/null 将标准输出 (STDOUT) 重定向到 "bit bucket"

& 在后台设置整个命令行为运行

这行代码更冗长,可能更容易理解。

有点多余的答案,但我更喜欢这种格式:

arpspoof -t 10.1.1.1 10.1.1.2 >/dev/null 2>&1

请确保您没有后台进程仍然 运行(因此仍在写入 console/screen)来自先前尝试重定向输出。