Measure disk space of certain file types in aggregate

Dan picture Dan · Aug 31, 2009 · Viewed 17.4k times · Source

I have some files across several folders:

/home/d/folder1/a.txt
/home/d/folder1/b.txt
/home/d/folder1/c.mov
/home/d/folder2/a.txt
/home/d/folder2/d.mov
/home/d/folder2/folder3/f.txt

How can I measure the grand total amount of disk space taken up by all the .txt files in /home/d/?

I know du will give me the total space of a given folder, and ls -l will give me the total space of individual files, but what if I want to add up all the txt files and just look at the space taken by all .txt files in one giant total for all .txt in /home/d/ including both folder1 and folder2 and their subfolders like folder3?

Answer

Barry Kelly picture Barry Kelly · Aug 31, 2009

find folder1 folder2 -iname '*.txt' -print0 | du --files0-from - -c -s | tail -1