Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I silence the HEAD of a curl request while using the silent flag?

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.

like image 802
Trevor Hickey Avatar asked Jun 23 '15 13:06

Trevor Hickey


People also ask

How do you silence curl output?

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 flag in curl request?

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.

What does curl -- fail mean?

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.


2 Answers

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.

like image 84
Joe Avatar answered Sep 25 '22 02:09

Joe


Try this:

curl --silent "www.site.com" > file.txt

If you wish, you can use the shorthand -s.

like image 31
NarūnasK Avatar answered Sep 25 '22 02:09

NarūnasK