Linux 如何让 cURL 不显示进度条?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7373752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:07:47  来源:igfitidea点击:

How do I get cURL to not show the progress bar?

linuxbashunixscriptingcurl

提问by adammenges

I'm trying to use cURL in a script and get it to notshow the progress bar.

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

I've tried the -s, -silent, -S, and -quietoptions, but none of them work.

我尝试了-s-silent-S-quiet选项,但它们都不起作用。

Here's a typical command I've tried:

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

curl -s http://google.com > temp.html

I only get the progress bar when pushing it to a file, so curl -s http://google.comdoesn't have a progress bar, but curl -s http://google.com > temp.htmldoes.

我只在将其推送到文件时获得进度条,所以curl -s http://google.com没有进度条,但curl -s http://google.com > temp.html有。

采纳答案by unutbu

curl -s http://google.com > temp.html

works for curl version 7.19.5 on Ubuntu 9.10 (no progress bar). But if for some reason that does not work on your platform, you could always redirect stderr to /dev/null:

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

curl  http://google.com 2>/dev/null > temp.html

回答by Tom Zych

Not sure why it's doing that. Try -swith the -ooption to set the output file instead of >.

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

回答by Bill Healey

I found that with curl 7.18.2 the download progress bar is not hidden with:

我发现使用 curl 7.18.2 下载进度条没有隐藏:

curl -s http://google.com > temp.html

but it is with:

但它与:

curl -ss http://google.com > temp.html

回答by chmac

In curl version 7.22.0 on Ubuntu and 7.24.0 on OSX the solution to not show progressbut to show errorsis to use both -s(--silent) and -S(--show-error) like so:

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

curl -sS http://google.com > temp.html

This works for both redirected output > /some/file, piped output | lessand outputting directly to the terminal for me.

这适用于重定向输出> /some/file、管道输出| less和直接输出到我的终端。

回答by Daniel Hajduk

Some time ago wrote a simple script to do the scrapping for searching for example specific versions of jdk installed:

前段时间写了一个简单的脚本来进行搜索,例如搜索安装的特定版本的 jdk:

#!/bin/bash
REPO_TAG_URL=

SEARCH=`curl -s $REPO_TAG_URL`
NEXT_PAGE=`echo $SEARCH | jq -r .next`

echo $SEARCH | jq '.results[].name'

while [[ $NEXT_PAGE != 'null' ]]; do
    SEARCH=`curl -s $NEXT_PAGE`
    NEXT_PAGE=`echo $SEARCH | jq -r .next`
    echo $SEARCH | jq '.results[].name'
done

echo "Thats all folks"

You use it like this: ./script.sh https://registry.hub.docker.com/v2/repositories/library/tomcat/tags/

你像这样使用它: ./script.sh https://registry.hub.docker.com/v2/repositories/library/tomcat/tags/

回答by RLynch59

On MacOS 10.13.6 (High Sierra), the '-ss' option works. It is especially useful inside perl, in a command like curl -ss --get {someURL}, which frankly is a whole lot more simple than any of the LWP or HTTP wrappers, for just getting a website or webpage's contents.

在 MacOS 10.13.6 (High Sierra) 上,'-ss' 选项有效。它在 perl 中特别有用,在类似 的命令中curl -ss --get {someURL},坦率地说,它比任何 LWP 或 HTTP 包装器都要简单得多,只需获取网站或网页的内容。