To determine the size of a file at a remote URL without downloading it, you can use an HTTP HEAD request.
This type of request retrieves only the HTTP headers, which often include the Content-Length
header that
indicates the file size in bytes.
curl -sI https://datasets-documentation.s3.eu-west-3.amazonaws.com/uk-house-prices/postgres/uk_prices.sql.tar.gz | awk '/Content-Length/ {
size=$2;
split("B KB MB GB TB", unit);
for (i=1; size>=1024 && i<5; i++) size/=1024;
printf("%.2f %s\n", size, unit[i])
}'
Alternatively,
curl -sI "https://datasets-documentation.s3.eu-west-3.amazonaws.com/uk-house-prices/postgres/uk_prices.sql.tar.gz" | \
grep -i content-length | \
awk '{b=$2; k=b/1024; m=k/1024; g=m/1024;
if(g>=1) printf "%.2f GB\n",g;
else if(m>=1) printf "%.2f MB\n",m;
else if(k>=1) printf "%.2f KB\n",k;
else printf "%d B\n",b;}'