During a nightly health-check script you must test whether the internal endpoint https://service.example.local/ is alive. The check has three strict requirements:
Do not download the response body (only a HEAD request is acceptable).
Show only the HTTP status code on standard output so the code can be captured by the monitoring system.
Cause the shell to return a non-zero exit status automatically when the server answers with any 4xx or 5xx error.
Which single curl command meets all of these requirements?
The combination of options -I, -s, -o /dev/null, -w "%{http_code}\n", and -f delivers exactly what the script needs. -I performs a true HEAD request, so no body is transferred. -s suppresses the progress meter, and -o /dev/null discards anything that might still be written to standard output. -w prints just the value of the http_code variable, giving a clean numeric status line. Finally, -f makes curl exit with status 22 when the response code is 400 or higher, so the calling script can treat any 4xx/5xx reply as a failure.
The other commands miss at least one requirement:
The version that omits -I still issues a GET and therefore transfers the response body.
The variant that leaves out -o /dev/null lets the response headers appear on stdout, so the output is not limited to the status code.
Using -X HEAD only changes the request word and does not behave like a real HEAD request; it can hang if the server sets an inappropriate Content-Length. Therefore it is not reliable for scripted checks.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the -f option in the curl command?
Open an interactive chat with Bash
Why is -I preferred over -X HEAD for HEAD requests in curl?
Open an interactive chat with Bash
What does -w "%{http_code}\n" accomplish in the curl command?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
System Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .