wget: check if the file exists, but not download








--spider option can be used:

wget --spider <url>
you can use it to resolve the address: e.g.
$ wget --spider http://ligman.me/NyWB7H
Spider mode enabled. Check if remote file exists.
--2012-08-07 09:33:33--  http://ligman.me/NyWB7H
Resolving ligman.me... 69.58.188.49
Connecting to ligman.me|69.58.188.49|:80... connected.
HTTP request sent, awaiting response... 301 Moved
Location: http://download.microsoft.com/download/B/B/F/BBF0C6F3-6E36-4979-8C43-DE165AD7AE34/SP2010 Kerberos Guide.docx [following]
Spider mode enabled. Check if remote file exists.
--2012-08-07 09:33:34--  http://download.microsoft.com/download/B/B/F/BBF0C6F3-6E36-4979-8C43-DE165AD7AE34/SP2010%20Kerberos%20Guide.docx
Resolving download.microsoft.com... 203.13.161.16, 203.13.161.17
Connecting to download.microsoft.com|203.13.161.16|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7594191 (7.2M) [application/octet-stream]
Remote file exists.


You can also run it with -q option (quiet mode).
wget --spider http://ligman.me/NyWB7H
echo $?
If it returns 0 means the file exists. Non zero value means the file does not exist.


No comments:

Post a Comment