管道时卷曲如何打印到终端

vik*_*mun 6 command-line redirect curl

当我 curl一个文件并将其通过管道传输到文件或其他命令时,我会在终端中看到输出。我不确定这是怎么发生的,因为管道应该从 curl 获取所有输出,对吗?

例如:

$ curl http://www.archive.org/stream/Pi_to_100000000_places/pi.txt > /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  129M    0  129M    0     0  22.5M      0 --:--:--  0:00:05 --:--:-- 24.7M
Run Code Online (Sandbox Code Playgroud)

编辑

我像这样使用卷曲:

curl http://www.archive.org/stream/Pi_to_100000000_places/pi.txt | some_other_command > some_file
Run Code Online (Sandbox Code Playgroud)

我不想将状态通过管道传递给 some_other_command,我只是想知道它是如何显示状态的。但是,展示了如何重定向添加到答案中的两个流,所以不要删除它。

mur*_*uru 9

通常有两种可用的输出流:标准输出和标准错误。实际上,在终端中运行时,两者都向终端发送数据。>仅重定向标准输出,curl 将进度数据打印到标准错误。要抑制两者,请使用以下之一:

curl ... > /dev/null 2>&1
curl ... &> /dev/null    # bash's combined redirection operator
curl -s ...    # -s, --silent: Silent or quiet mode. Don't show progress meter or error messages.
Run Code Online (Sandbox Code Playgroud)

将两者都发送到管道:

curl ... 2>&1 | ...
curl |& ...    # bash's combined pipe
Run Code Online (Sandbox Code Playgroud)

除非您使用|&or&>运算符,否则所有流都将独立重定向。

另见: