Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get total space of filenames matching a pattern?

I am trying to get the total disk usage of log files under a folder using find | du -s. du is not summarizing.

find ${ROOT_FOLDER} -name "*.log" -print0 | du -hs --files0-from=-

The command lists every matching file and the disk usage of the file. No summary for all files.

Are there additional options that can be specified to the summary for all files?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You want -c (so, with your other switches, -hsc ) which should provide a grand total for du (see man7.org/linux/man-pages/man1/du.1.html)

/ # find / -name "*.log" -print0 |  du -hs --files0-from=-
1.0M    /tmp/1.log
2.0M    /var/log/2.log
/ # find / -name "*.log" -print0 |  du -hsc --files0-from=-
1.0M    /tmp/1.log
2.0M    /var/log/2.log
3.0M    total
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading