Created
October 7, 2018 02:49
-
-
Save sobujbd/e1ec58c52824d569bee3c7ee8f1a4921 to your computer and use it in GitHub Desktop.
File Size | Shell Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # read -e -p "Enter File URL: " fileUrl | |
| # if [ -z "${fileUrl}" ];then | |
| # echo "Missing File URL!" | |
| # exit | |
| # fi | |
| bytesToHuman() { | |
| b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Y,Z}iB) | |
| while ((b > 1024)); do | |
| d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))" | |
| b=$((b / 1024)) | |
| let s++ | |
| done | |
| echo "$b$d ${S[$s]}" | |
| } | |
| URL=$1 | |
| if [ -z "$URL" ]; then | |
| printf "\nUsage:\n\t filesize <file url>\n\n" | |
| exit 0; | |
| fi | |
| FILE_NAME=$(basename "$URL") | |
| #FILE_SIZE=$(curl "$URL" --silent --write-out '%{size_download}\n' --output /dev/null) | |
| #GZIP=$(curl "$URL" --silent -H 'Accept-Encoding: gzip,deflate' --write-out '%{size_download}\n' --output /dev/null) | |
| FILE_SIZE=$(http --headers "$URL" | grep -i Content-Length | awk '{print $2}') | |
| printf "\nFile Name:\n$FILE_NAME" | |
| printf "\nFile Size: $(bytesToHuman $FILE_SIZE)\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment