curl hide progress bar output on Linux/Unix shell scripts

last updated in Categories , ,

I am a new Ubuntu Linux user. I am writing a shell script and using the curl command to grab URL output using curl https://example.com/data/api/$key/hash.html. However, the curl command is outputting complete progress information that my script does not need it. How can I get curl command not to show the progress bar output? How can I hide curl command output? Is there is a simple way for silencing curl’s progress output on an Ubuntu Linux desktop?

Introduction: cUrl is both an application library and command for downloading files or performing requests on the Web. The curl command works on Linux, Windows, macOS, *BSD and Unix-like system. This page shows how to hide progress bar output on a Linux or Unix-like system when using the curl command.

curl hide progress bar output when using shell scripts

The procedure to hide curl progress bar is to pass the -s or --silent option to the curl command:

  1. Open the terminal app
  2. Type the command: curl -s https://www.cyberciti.biz/ > /tmp/output.html
  3. Verify it with the cat command: cat /tmp/output.html

Let us see all commands and some examples in details.

How can I get cURL not show the progress bar on Linux

Consider the following simple command:
$ curl https://www.cyberciti.biz/ > /tmp/output.html
How to get cURL command not show the progress bar

How to silencing curl command’s progress output

Run command:
$ curl -s https://www.cyberciti.biz/ > /tmp/output.html
OR
$ curl --silent https://www.cyberciti.biz/ > /tmp/output.html
You can use the grep command or egrep command as follows too:
$ curl -s https://www.kernel.org/ | grep -A 2 '<td id="latest_button">'
Silencing Curl Command's Progress Bar Output

Understanding the -s and -S options

From the curl man page:

The -s or --silent option act as silent or quiet mode. Don’t show progress meter or error messages. Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect it.

Use -S, --show-error in addition to this option to disable progress meter but still show error messages.

The following command will silence the progress output without silencing real errors:
$ curl -sS https://www.example.com/foo/bar.cgi > /tmp/out.txt
OR
$ curl -sS https://www.cyberciti.biz/ > /dev/null

Eliminating progress bar on an older version of curl running on Unix-like system

If you are using an older version of curl and cannot update curl that has -s option, try:
$ curl https://www.nixcraft.com/ 2>/dev/null > /tmp/nix.html
OR
$ curl https://www.nixcraft.com/ 2>/dev/null | grep '<title>'
curl hide progress bar output on Linux macOS BSD Unix

Conclusion

You just learned how to eliminating curl command’s progress bar output when using with shell scripts. For more info see curl command man page.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com