Wednesday, March 24, 2021

How to find the file size of a remote HTTP object?

There are times when you need to know the file size of an HTTP object without actually downloading the file. This little trick comes in very handy when web servers respond with the Content-Length of an object in the HEAD request itself.

Using curl command:


curl -sI | grep Content-Length

Content-Length: 2877227008

Let’s try and make this human-friendly:

curl -sI | grep Content-Length | sed 's/[^0-9]//g' | numfmt --to=si


Where The Numfmt command will convert the numbers to/from human-readable format.

No comments:

Post a Comment