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

前端 未结 2 1470
闹比i
闹比i 2020-12-23 12:25

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 m

相关标签:
2条回答
  • 2020-12-23 13:02
    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.

    0 讨论(0)
  • 2020-12-23 13:05

    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.

    0 讨论(0)
提交回复
热议问题