What do the curl flags -s, -L, -o, -f and -I do?
-s hides the progress meter, -L follows redirects, -o saves the body to a file, -f makes curl fail with a non-zero exit code on HTTP errors, and -I fetches only the headers. A common combination in scripts is curl -fsSL.
Explain it simply
By default curl is quiet about failure: a 404 page is printed like a success and the exit code is 0. Scripts need the flags below to behave properly.
-ssilent: no progress bar. Pair with-Sso real errors still show.-Lfollow redirects. Without it, a 301 from http to https returns an empty page.-o filesave the body to a named file;-Ouses the remote file name.-ffail on HTTP errors (400 and above): no body, exit code 22.-IHEAD request: print only response headers.-w '%{http_code}'prints the status code after the transfer.
The common installer pattern curl -fsSL URL | bash means: be quiet, fail properly, show errors, follow redirects. It is convenient but dangerous: you run unseen code, so download first and read it.
Example
code=$(curl -s -o /dev/null -w '%{http_code}' https://example.com)
echo "$code"
# 200
curl -fsSL -o get.sh https://example.com/get.sh || echo "download failed"What to say in the interview
"-s quiets progress, -L follows redirects, -o saves to a file, -f turns HTTP errors into a failing exit code and -I fetches headers only. In scripts I use -fsSL and check the exit status, or -w to read the status code."
Common mistakes
- Assuming curl exits non-zero on a 404; it does not without -f.
- Piping curl straight into bash without reading the script.