I started a few weeks with Linux bash programming, but I'm struggling with a problem: How can I get the size of multiple directories (path saved on a .txt file) and then, write into another file, the directory path, followed by size and the total size occupied by that directories. I already tried this, but I'm not sure:
totsize=0
while read -r diretory; do
size=$(du -ch "$directory")
echo "$diretory size: $size" > "$homedir/$filename2"
$totsize += $(du -c "$homedir/$diretorio")
done < "$homedir/diretories.txt"
sudo echo "total size: $totsize" >> "$homedir/$filename2"
Thanks in advance (and sorry for bad english)