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:


Example:


curl -sI https://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso | grep Content-Length


Content-Length: 2877227008


Let’s try and make this human-friendly:


curl -sI https://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso | grep Content-Length | sed 's/[^0-9]//g' | numfmt --to=si

2.9G



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


No comments:

Post a Comment