When I run the curl command and direct the data to a file, I get back the content of the site as expected.
$ curl "www.site.com" > file.txt
$ head file.txt
Top of site
...
However, this command shows a progress bar, which I do not want:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 328k 100 328k 0 0 467k 0 --:--:-- --:--:-- --:--:-- 467k
I can silence the progress bar by passing the -silent
flag, but then my file output will have head content attached:
$ curl -silient "www.site.com" > file.txt
$ head file.txt
HTTP/1.1 200 OK
Content-Security-Policy: default-src 'none'
X-XSS-Protection: 1; mode=block
X-Frame-Options: deny
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=31536000
ETag: "29647904ffa6a6b36cf3483b325138cab9447a13"
Content-Type: text/plain; charset=utf-8
Cache-Control: max-age=300
Content-Length: 335978
How can I silence both the progress bar and avoid getting head content sent to the file?
Based on the provided flags, it seems like I can only get one or the other.
This is what I'm doing right now to solve the problem, but I'm not sure if it's a good idea to pipe the progress bar and possibly any errors into /dev/null.
curl "www.site.com" > file.txt 2> /dev/null
The reason I don't think this is a good idea is because it may interfere with the actual errors that I care about. I'd like to utilize the silent
flag if that's what it was intended for.
I've also tried all the same commands using the -o
to output to a file, but to no prevail.
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.
What is a flag in Curl? A flag is a command-line parameter that denotes a specific action in Curl. Curl has over three hundred command-line options, and the number of options increases over time. You can add the listed flags to the Curl command and enter the URL.
The --fail option has turned out to be a surprisingly popular option but users have often repeated the request to also make it possible to get the body stored. --fail makes curl stop immediately after having received the response headers – if the response code says so.
You need to use --silent
with two dashes. Your “option” -silient
(sic!) enables the -s
, -i
, -l
, -e
, -n
and -t
options.
-i
is what includes the HTTP header.
Try this:
curl --silent "www.site.com" > file.txt
If you wish, you can use the shorthand -s
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With