Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use wget to check , but not download

Tags:

wget

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

like image 894
mike628 Avatar asked Jun 07 '11 11:06

mike628


People also ask

How do you test if wget is working?

The wget package is pre-installed on most Linux distributions today. To check whether the Wget package is installed on your system, open up your console, type wget , and press enter. If you have wget installed, the system will print wget: missing URL .

Does wget download a file?

Downloading a file In order to download a file using Wget, type wget followed by the URL of the file that you wish to download. Wget will download the file in the given URL and save it in the current directory.

What is wget used for?

What is wget? Wget is a free GNU command-line utility tool used to download files from the internet. It retrieves files using HTTP, HTTPS, and FTP protocols. It serves as a tool to sustain unstable and slow network connections.

What can I use instead of wget?

The best alternative is aria2, which is both free and Open Source. Other great apps like Wget are uGet, cURL, ArchiveBox and HTTPie. Wget alternatives are mainly Download Managers but may also be Website Downloaders or HTTP Clients.


2 Answers

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 $? 

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.

like image 74
Shadikka Avatar answered Nov 05 '22 21:11

Shadikka


If you want to check quietly via $? without the hassle of grep'ing wget's output you can use:

wget -q "http://blah.meh.com/my/path" -O /dev/null 

Works even on URLs with just a path but has the disadvantage that something's really downloaded so this is not recommended when checking big files for existence.

like image 32
3ronco Avatar answered Nov 05 '22 21:11

3ronco