最近想用curl獲取到訪問某網站的返回狀態碼,靈機一想,curl好像可以實現.命令如下:
curl -s -w "%{http_code}\n" -o /dev/null www.baidu.com
-w 也支持其他的選項,如想知道某網站的解析速度,用如下命令實現:
curl -o /dev/null -s -w %{time_connect}:%{time_namelookup}:%{time_total} www.baidu.com
詳細的curl -w支持選項見如下鏈接:
https://ec.haxx.se/usingcurl/usingcurl-verbose/usingcurl-writeout#available-write-out-variables
真香定律!