Reputation: 796
I have a list.txt where there's a file link per line. Need a command that shows me the size of each file, in either bytes or human readable format.
Upvotes: 0
Views: 465
Reputation: 796
This is to show a single file size in bytes:
wget --spider url 2>&1 | grep -o -P '(?<=Length: ).*(?= \()'
This is to write to a text file the size of each file from a link list file. Note that the resulting file will only be populated when the process ends.
wget --spider -i list.txt 2>&1 | grep -o -P '(?<=Length: ).*(?= \()' > sizes.txt
If you want to write the size each time a file is checked:
while read line ; do wget --spider "$line" 2>&1 | grep -o -P '(?<=Length: ).*(?= \()' >> sizes.txt ; done < list.txt
To sum up the size in bytes of all links just to the following:
awk '{s+=$1} END {print s}' sizes.txt
Upvotes: 1