用 curl 查看网站的 HTTP 状态码

用 curl 一条命令只打印网址的 HTTP 状态码和响应时间,适合在终端里做健康检查和快速排查。

Linuxcurl 请求诊断低风险
运行 curl -s -o /dev/null -w "%{http_code}\n" https://example.com,即可打印该网站的 HTTP 状态码。

01命令

命令
$ curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" https://example.com

02作用说明

-o /dev/null 会把网页内容丢掉,只留汇总输出;-w 在请求结束后输出指定变量——%{http_code} 是状态码(200、301、404、500 等),%{time_total} 是整个请求耗时(秒)。这很适合写进脚本或 cron 做简易监控:只要不是 2xx 就说明网站出状况了。想跟随重定向后再报最终状态码,加 -L 即可。

03风险

风险低风险
!注意: 有些服务器对 curl 和真实浏览器返回不同状态码(反爬或压缩差异),所以这里出现 403 不一定代表用户侧网站挂了。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • curl(1) — Linux manual page
    Arch Linux · community · 2026-09-17
    依据: Documents -o, -s and -w/--write-out variables such as http_code and time_total for summarizing a transfer.
  • curl man page — -w / --write-out and %{http_code}
    curl · vendor-doc · 2026-09-17
    依据: Documents the --write-out variables including http_code and time_total, used to print the response status and timing after a request.

最后验证: 2026-09-18 · 分类: 网络

06相关方案