linux - 如何处理后台 linux 任务的输出

标签 linux bash command-line background-process

我有一个不断回显信息的任务。

例如,如果您执行 git clone 并且您希望将该任务发送到后台(通过使用 & 符号)

git clone https://github.com/mrdoob/three.js.git &

然后git clone操作就是不断的用git clone进程的新百分比刷新屏幕,即:

Receiving objects:  47% (22332/47018), 92.53 MiB | 480 KiB/s   1410/47018), 7.18 MiB | 185 KiB/s
Receiving objects:  53% (24937/47018), 99.40 MiB | 425 KiB/s   1410/47018), 7.18 MiB | 185 KiB/s 

因此我无法继续在前台执行其他操作,因为这些更新使我无法看到我正在尝试编写的内容。

你们能告诉我如何有效地将这样一个冗长的任务发送到后台吗?

非常感谢!

最佳答案

您可以让进程将其输出写入文件(如果您需要稍后查看),如下所示:

git clone https://github.com/mrdoob/three.js.git >output.txt &

或者像这样完全丢弃输出:

git clone https://github.com/mrdoob/three.js.git >/dev/null &

编辑:

您还可以通过将 & 替换为 2>&1 &

来在上述任一选项中包含发送到 stderror 的任何错误消息

关于linux - 如何处理后台 linux 任务的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14630104/

相关文章:

git - 致命的 : This operation must be run in a work tree

linux - 您对 TaskJuggler 的体验如何?

c - linux/kernel.h 中的 sysinfo 结构

linux - BASH - 删除超过 3 个月的文件?

command-line - 在不安装 key 的情况下验证 gpg 签名

python - 命令提示符/Anaconda 命令提示符无法在 Windows 11 中打开

linux - 更改目录并使用 #!bin/bash 文件运行命令

c - 来自对象符号表的结构成员详细信息

bash - 在 Bash 函数中使用 getopts

bash - 将 bash 中的命令输出解析为变量