我可以使用 wget 来检查,但不能下载吗

问题描述:

我可以使用 wget 来检查 404 而不是实际下载资源吗?如果是这样怎么办?谢谢

Can I use wget to check for a 404 and not actually download the resource? If so how? Thanks

有命令行参数 --spider 正是为此.在这种模式下,wget 不下载文件,如果找到资源,它的返回值为零,如果没有找到,则返回非零值.试试这个(在你最喜欢的 shell 中):

There is the command line parameter --spider exactly for this. In this mode, wget does not download the files and its return value is zero if the resource was found and non-zero if it was not found. Try this (in your favorite shell):

wget -q --spider address
echo $?

或者,如果您想要完整输出,请关闭 -q,因此只需 wget --spider address.-nv 显示了一些输出,但没有默认值那么多.

Or if you want full output, leave the -q off, so just wget --spider address. -nv shows some output, but not as much as the default.