Short command to find total size of files matching a wild card

Try du to summarize disk usage:

du -csh *.jpg

Output (for example):

8.0K sane-logo.jpg
16K sane-umax-advanced.jpg
28K sane-umax-histogram.jpg
24K sane-umax.jpg
16K sane-umax-standard.jpg
4.0K sane-umax-text2.jpg
4.0K sane-umax-text4.jpg
4.0K sane-umax-text.jpg
104K total

du does not summarize the size of the files but summarizes the size of the used blocks in the file system. If a file has a size of 13K and the file system uses a block size of 4K, then 16K is shown for this file.


You can use this function :

dir () { ls -FaGl "${@}" | awk '{ last_size += $4; print }; END { print last_size }'; }

also you can use this command this is shorter and give you better result!

find YOUR_PATH -type f -name '*.jpg' -exec du -ch {} +

Tags:

Linux

Bash