I have a download link to a large file. You need to be logged in to the site, so a cookie is used. The download link redirects to another URL. I'm able to download the file with wget but I only want the output of the "real" direct download link. wget does exactly this before starting the download
Location: https://foo.com/bar.zip [following]
Is there a way to make wget stop and not actually downloading the file? The solutions I found recommend redirecting to dev/null but this would still download the file. What I want is wget following the redirects but not actually starting the download.
I couldn't find a way to do it with wget
, but I found a way to do it with curl
:
curl https://openlibrary.org/data/ol_dump_latest.txt.gz -s -L -I -o /dev/null -w '%{url_effective}'
This only downloads the HEAD of the page (and sends it to /dev/null
), so the file itself is never downloaded.
(src: https://stackoverflow.com/a/5300429/2317712 )
Going off of @qqilihq's comment to the curl
answer, this will first strip out the line starting with "Location:" then remove the "Location: " from the beginning and the " [following]" from the end using awk
. Not sure if I would use this as it looks like a small change in the wget
output could make it blow up. I would use the curl
answer myself.
wget --max-redirect=0 http://example.com/link-to-get-redirec-url-from 2>&1 | awk '/Location: /,// { print }' | awk '{print $2}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With