357

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

1

3 Answers 3

520

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
5
  • 44
    If you want only errors add the -S flag curl -s -S 'example.com' > /dev/null Nov 3, 2016 at 11:55
  • 3
    Note that you can't do curl -o /dev/null; it will throw a write error. Feb 10, 2017 at 22:12
  • 1
    But you can do curl ... 2>/dev/null to redirect stderr only. Sep 14, 2017 at 20:23
  • 3
    @KeithTyler curl https://www.google.com -o /dev/null succeeds without errors for me. I'm using curl-7.58.0.
    – x-yuri
    Apr 4, 2018 at 13:29
  • 1
    that in my opinion means wget should be used instead of curl for downloading files.
    – Vishrant
    Jan 18, 2019 at 21:35
141

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.

2
  • 19
    If you still want errors to be shown you can add the --show-error parameter too.
    – Simon East
    Mar 26, 2018 at 23:30
  • Even using -sS it still display the headers for me :(
    – Freedo
    Aug 27, 2019 at 5:59
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .