Reputation:
curl -o foo.txt http://test.barrycarter.info/emptyfile.txt
curl -O http://test.barrycarter.info/emptyfile.txt
I just tried both the above, and neither foo.txt nor emptyfile.txt were created.
How can I make curl create them? Knowing that a file (URL) exists and is empty can be useful.
In particular, I'm trying to mirror geonames daily updates, and it so happens that today's "http://download.geonames.org/export/dump/alternateNamesDeletes-2015-05-28.txt" file is empty. It would be useful to know this instead of simply not downloading it.
(Note: I created an emptyfile above for testing, since geonames' file will disappear within a day)
Upvotes: 3
Views: 1799
Reputation: 58004
Curl didn't use to store anything on zero byte downloads, but it does since version 7.42.0.
Upvotes: 4
Reputation: 193
Can you use wget
instead? That will do exactly what you want.
If not, try this:
curl -v -o file.txt url://... 2> log.txt
grep '^HTTP/.* 404' log.txt
The return code from grep
will be 0 if the file was not found, 1 otherwise.
Upvotes: 1