Iam 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.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | No |
Requirements | Linux or Unix terminal |
Category | Linux shell scripting |
Prerequisites | curl commmand |
OS compatibility | BSD • Linux • macOS • Unix • WSL |
Est. reading time | 4 minutes |
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:
- Open the terminal application on your Linux/Unix.
- Type the command (pass -s option to curl to hide progress bar):
$ curl -s https://your-dot-com-domain-name-here/ > /tmp/output.html
- 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 (replace www.cyberciti.biz with your domain name):$ curl https://www.cyberciti.biz/ > /tmp/output.html
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">'
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>'
Hiding curl output in shell scripts
The syntax is same. For example see if remote web-server produce ‘HTTP/2 200’ code as follows$ curl -s -I https://www.cyberciti.biz | grep 'HTTP/2 200'
Let us try out:
#!/usr/bin/env bash # Purpose: Check whether a website is up or down using the CLI # Author: Vivek Gite {https://www.cyberciti.biz} under GPL v2.x+ # Requirments: Bash v3.x+ and curl running on Linux/Unix-like systems # ------------------------------------------------------------------- r="$1" out="" if [ "$r" == "" ] then echo "Usage: $0 url" exit 1 fi out=$(curl -k -I -L -s "$r" | grep -E -i 'http/[[:digit:]]*') if [ "$out" != "" ] then if [[ $out =~ .*200.* ]] then echo "✅ Site is up with HTTP code 200" else echo "❌ Site did not return HTTP code 200" echo "Headers info for $r:" echo "$out" fi fi
Run it as follows:./script domain
./script nixcraft.com
./script cyberciti.biz
curl -L -o /dev/null -s -I -w '%{http_code}\n' url curl -L -o /dev/null -s -I -w '%{http_code}\n' https://cyberciti.biz
Understanding hide curl output options
Option used to hide curl output are as follows:
- -s : Hide curl output especially progress bar.
- -k : Allows curl to proceed and operate even for server connections otherwise considered insecure. For example, self-singed TLS.
- -I : Fetch the HTTP headers only.
- -L : Follow URL/domain when we see header and a 3XX response code.
- -o /dev/null : Sed output to /dev/null instead of stdout (screen). See BASH Shell Redirect Output and Errors To /dev/null for more info.
- -w '%{http_code}\n' : Display the numerical response code that was found in the last retrieved HTTP(S) or FTP(s) transfer. The -w option forces curl to show information on screen after a completed transfer.
The grep command/egrep command used to filter curl command HTTP headers:
- -E : Turn on extended regular expressions with grep.
- -i : Ignore case. In other words match HTTP, http, and so on.
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 using the man command or help command:$ man curl
$ curl --help