본문 바로가기
딥러닝

다운로드 할 파일 총 용량 알아보는 법

by jennyiscoding 2024. 12. 11.

코드:

#!/usr/bin/env bash

# URL 파일 경로
URL_FILE=$1

# URL 파일 존재 확인
if [ ! -f "$URL_FILE" ]; then
    echo "Error: URL file '$URL_FILE' not found."
    exit 1
fi

# 전체 파일 크기 초기화
total_size=0

# 각 URL에 대해 파일 크기 확인
while IFS= read -r url; do
    if [[ -z "$url" || "$url" =~ ^# ]]; then
        continue
    fi

    # 파일 크기 확인 (HEAD 요청)
    size=$(wget --spider --server-response "$url" 2>&1 | grep -i "Content-Length" | awk '{print $2}' | tr -d '\r')

    if [[ -n "$size" ]]; then
        echo "File: $url --> Size: $((size / 1024 / 1024)) MB"
        total_size=$((total_size + size))
    else
        echo "Warning: Could not determine size for $url"
    fi
done < "$URL_FILE"

# 총 파일 크기 출력
echo "--------------------------------------"
echo "Total Size: $((total_size / 1024 / 1024)) MB"
echo "--------------------------------------"

 

돌리는 방법: ./check_file_size.sh k600_dataset_train_fall.txt

결과:

root@60d2390e523f:/workspace/tools/data/kinetics# ./check_file_size.sh k600_dataset_train_fall.txt
File: https://s3.amazonaws.com/kinetics/600/train/falling off chair.tar.gz --> Size: 424 MB
File: https://s3.amazonaws.com/kinetics/600/train/falling off chair.tar.gz --> Size: 424 MB
--------------------------------------
Total Size: 849 MB
--------------------------------------

 

txt파일:

https://s3.amazonaws.com/kinetics/600/train/falling off chair.tar.gz
https://s3.amazonaws.com/kinetics/600/train/falling off chair.tar.gz
https://s3.amazonaws.com/kinetics/600/train/punching person (boxing).tar.gz