7

I want to download a file from a server, but before doing so I would like to know the actual file size. I know that wget will display the filesize when the download is started, but this actually starts the download process also.

How can I just know the filesize of a remote file on an http server?

1
  • 1
    would this suffice: size_remote=$(curl -sI "http://www.example.com/testfile.bin" | awk '/Content-Length/ { print $2 }') ?
    – Rinzwind
    Dec 12, 2013 at 19:49

1 Answer 1

9

You can try typing:

wget --spider

It gives for example 134K:

$ wget --spider "https://askubuntu.com/questions/389910/get-the-size-of-a-remote-file-from-terminal/389920#389920"
Spider mode enabled. Check if remote file exists.
--2019-09-27 20:34:46--  https://askubuntu.com/questions/389910/get-the-size-of-a-remote-file-from-terminal/389920
Resolving askubuntu.com (askubuntu.com)... 151.101.193.69, 151.101.129.69, 151.101.65.69, ...
Connecting to askubuntu.com (askubuntu.com)|151.101.193.69|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 136873 (134K) [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.
2
  • Solves my problem :)
    – Hashken
    Dec 12, 2013 at 20:00
  • Similar to curl --head URI, it fetches only the http req header (HEAD method) Sep 27, 2019 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.