seriousdev seriousdev - 3 months ago 22x
Bash Question

How to get remote file size from a shell script?

Is there a way to get the size of a remote file like

in shell script?


You can download the file and get its size. But we can do better.

Use curl to get only the response header using the -I option.

In the response header look for Content-Length: which will be followed by the size of the file in bytes.

$ URL=""
$ curl -sI $URL | grep Content-Length
Content-Length: 134

To get the size use a filter to extract the numeric part from the output above:

$ curl -sI $URL | grep Content-Length | awk '{print $2}'