Zgodna komanda sa zbirnu veličinu više fajlova

Dakle ako u jednom folderu imate određeni broj fajlova čija vam zbirna veličina treba, to se radi ovako (ako njihov ukupan broj ne prelazi 1200) :
# du -ch /apsolutna/putanja/ka/folderu/*deo-imena-fajla
…..
18M /apsolutna/putanja/ka/folderu/*deo-imena-fajla
3.9G total

Ako se ti fajlovi nalaze po različitim folderima, ili ako ih ima više od 1200 :
# find . -type f -iname ‘*deo-imena-fajla’ -print0 | xargs -r0 du -a| awk ‘{sum+=$1} END {print sum}’
Objašnjenje :
find . -type f -iname ‘*deo-imena-fajla’ -print0: Find all files with the (for example) extension jpg regardless of case (i.e. *.jpg, *.JPG, *.Jpg…) and output them (null-terminated).
xargs -r0 du -a: -r: Xargs would call the command even with no arguments passed, which -r prevents. -0 means null-terminated strings (not newline terminated).
awk ‘{sum+=$1} END {print sum}’: Sum up the file sizes output by the previous command

Comments are closed.