2014-09-03 80 views
0

我有一個list.txt,每行有一個文件鏈接。需要一個命令,以字節或人類可讀格式顯示每個文件的大小。如何使用wget獲取列表中每個鏈接文件的大小?

+0

這可能是一個很好的開始http://unix.stackexchange.com/questions/61132/how-do-i-use-wget-with-a-list-of-urls-and-their-corresponding-output-files – Hillboy 2014-09-03 16:54:06

+0

I需要一個具體的答案。 – Smeterlink 2014-09-03 16:58:04

回答

0

這是在字節顯示單個文件大小:

wget --spider url 2>&1 | grep -o -P '(?<=Length:).*(?= \()' 

這是寫入文本從鏈接列表文件文件中的每個文件的大小。請注意,生成的文件只會在過程結束時填充。

wget --spider -i list.txt 2>&1 | grep -o -P '(?<=Length:).*(?= \()' > sizes.txt 

如果你想每一個文件被選中時寫的大小:

while read line ; do wget --spider "$line" 2>&1 | grep -o -P '(?<=Length:).*(?= \()' >> sizes.txt ; done < list.txt 

要在各個環節的字節總結大小正好爲以下內容:

awk '{s+=$1} END {print s}' sizes.txt