如何让cURL不显示进度条?

ada*_*ges 518 unix linux bash scripting curl

我正在尝试在脚本中使用cURL并让它显示进度条.

我已经试过了-s,-silent,-S,和-quiet选择,但他们没有工作.

这是我尝试过的典型命令:

curl -s http://google.com > temp.html
Run Code Online (Sandbox Code Playgroud)

我将它推送到文件时只获得进度条,因此curl -s http://google.com没有进度条,但curl -s http://google.com > temp.html确实如此.

unu*_*tbu 520

curl -s http://google.com > temp.html
Run Code Online (Sandbox Code Playgroud)

适用于Ubuntu 9.10上的curl版本7.19.5(无进度条).但是如果由于某些原因在您的平台上无效,您可以始终将stderr重定向到/ dev/null:

curl  http://google.com 2>/dev/null > temp.html
Run Code Online (Sandbox Code Playgroud)

  • 我应该想到这一点.但它也会隐藏错误消息. (30认同)
  • IMO这个答案没用,因为它也隐藏了错误.我更喜欢下面的chmac答案. (11认同)

chm*_*mac 503

在Ubuntu上的curl版本7.22.0和OSX上的7.24.0上,不显示进度显示错误的解决方案是同时使用-s(--silent)和-S(--show-error):

curl -sS http://google.com > temp.html
Run Code Online (Sandbox Code Playgroud)

这适用于重定向输出> /some/file,管道输出| less和直接输出到终端.

  • @Jack从curl 7.67.0开始就有`--no-progress-meter`,请参阅下面的[我的答案](/sf/answers/4593409621/)。 (8认同)
  • 好一个!我自己使用`-S`,所以当我做`var = $(curl -S ...)时,它仍然产生输出.`-sS`解决了这个问题. (3认同)
  • 对于我的7.35使用-sS消除了进度表,但也删除了通常写入stdout的信息 - 这是我需要的,因为它包含写入磁盘的文件名而不是必须在请求中使用的(不同的)fileid.似乎没有办法简单地单独击败进度表! (3认同)
  • 顺便说一下,[Stack Overflow的Markdown实现目前不支持代码块的Github风格的三重````(https://meta.stackexchange.com/questions/125148/implement-style-markdown-code -blocks); 你必须缩进4个空格. (2认同)
  • 完全根据需要,因为标准误差很重要 (2认同)

小智 45

我发现使用curl 7.18.2时,下载进度条不会隐藏:

curl -s http://google.com > temp.html
Run Code Online (Sandbox Code Playgroud)

但它与:

curl -ss http://google.com > temp.html
Run Code Online (Sandbox Code Playgroud)


clo*_*ejo 16

自 curl 7.67.0 (2019-11-06)以来,有--no-progress-meter,它就是这样做的,没有别的。从手册页:

   --no-progress-meter
         Option to switch off the progress meter output without muting or
         otherwise affecting warning and informational messages like  -s,
         --silent does.

         Note  that  this  is the negated option name documented. You can
         thus use --progress-meter to enable the progress meter again.

         See also -v, --verbose and -s, --silent. Added in 7.67.0.
Run Code Online (Sandbox Code Playgroud)

它在 Ubuntu ?20.04 和 Debian ?11 (Bullseye) 中可用。

有关 curl 详细选项的一些历史,您可以阅读Daniel Stenberg 的博客文章

  • 这应该是公认的答案。所有其他答案都是错误的。 (3认同)

Tom*_*ych 6

不知道为什么会这样做.尝试-s使用-o选项来设置输出文件而不是>.