355

I'm making a curl request where it displays an html output in the console like this

<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/domain/public_html/wp-content/themes/explicit/functions/ajax.php:87) in <b>/home/domain/public_html/wp-content/themes/explicit/functions/ajax.php</b> on line <b>149</b><br />......

etc

I need to hide these outputs when running the CURL requests, tried running the CURL like this

curl -s 'http://example.com'

But it still displays the output, how can I hide the output?

Thanks

ivanleoncz
  • 487
  • 2
  • 7
  • 19
Rjack
  • 3,553
  • 2
  • 11
  • 4

3 Answers3

515

From man curl

-s, --silent 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.

So if you don't want any output use:

curl -s 'http://example.com' > /dev/null
FloHimself
  • 11,272
  • 3
  • 22
  • 24
140

This one looks more elegant to me:

curl --silent --output /dev/null http://example.com

Also, if you want to see the HTTP code:

curl --write-out '%{http_code}' --silent --output /dev/null http://example.com

Full documentation is here.

yegor256
  • 1,871
  • 3
  • 15
  • 12
2

One way to hide cURL output in the bash shell, is to redirect both stdout and stderr using the operator &> to /dev/null

curl http://example.com &> /dev/null
Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Miguel Mota
  • 244
  • 2
  • 6