Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get file size of a file to wget before wget-ing it?

I'm wondering if there is a way to check ahead of time the size of a file I might download via wget? I know that using the --spider option tells me if a file exists or not, but I'm interested in finding the size of that file as well.

like image 845
Dang Khoa Avatar asked Aug 08 '11 17:08

Dang Khoa


People also ask

How do I download large files using wget?

If so, use wget -c as suggested by @dtmland. Finally, wget does have an option to limit file size but it is not set by default. One possibility is that your sysadmin has set a limit by making wget an alias to something like wget --max-filesize N . To check if wget is an alias run alias wget .

What is wget spider?

The wget tool is essentially a spider that scrapes / leeches web pages but some web hosts may block these spiders with the robots. txt files. Also, wget will not follow links on web pages that use the rel=nofollow attribute. You can however force wget to ignore the robots.

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.


2 Answers

curl --head URL 

Look for "Content-Length:" in the output.

And thanks to Henning Makholm's comment:

wget --spider URL 

and look for "Length:" in the output.

like image 21
Keith Thompson Avatar answered Sep 21 '22 14:09

Keith Thompson


Hmm.. for me --spider does display the size:

$ wget --spider http://henning.makholm.net/ Spider mode enabled. Check if remote file exists. --2011-08-08 19:39:48--  http://henning.makholm.net/ Resolving henning.makholm.net (henning.makholm.net)... 85.81.19.235 Connecting to henning.makholm.net (henning.makholm.net)|85.81.19.235|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 9535 (9.3K) [text/html]     <------------------------- Remote file exists and could contain further links, but recursion is disabled -- not retrieving.  $  

(But beware that not all web servers will inform clients of the length of the data except by closing the connection when it's all been sent.)

If you're concerned about wget changing the format it reports the length in, you might use wget --spider --server-response and look for a Content-Length header in the output.

like image 190
hmakholm left over Monica Avatar answered Sep 20 '22 14:09

hmakholm left over Monica