Unixtrix: calculate size of all files of given extension

find . -name "*.AVI" -print0 | xargs -0 du -ch

Context:

cleaning up Erin’s Mac (more on that soon), I want to find out how much space is taken up by iPhoto movie files. iPhoto has crappy search features (read: none). So, cd ~/Pictures and then run the command above. (Answer: 26 GB.)

Explanation:

find by name all files with .AVI extension and print with null character delimiter. Use xargs to split input on null; pass to du -ch which prints a human-readable total size. (The null character business is needed because of spaces in file names.)

BTW, this is the first post in this category. I have been very bad about keeping a commonplace book, so to speak, for stupid unix/shell tricks. And of course I am worse about remembering them, so I need to put them somewhere as opposed to bash history. Hopefully I’ll actually keep this up…

This entry was posted in Meta, Nerdliness, Shell tricks. Bookmark the permalink.

2 Responses to Unixtrix: calculate size of all files of given extension

  1. Jeff Watkins says:

    Gosh, that seems so much easier than switch to Finder, type cmd-F, change kind to movies…

  2. cbd says:

    Yeah, I can fiddle with Spotlight to do the same search (add the search location, then search for “Name Ends With AVI”), but I (a) I have to be logged in as the right user, not working remotely; (b) every time I want to recalculate, I have to tweak Spotlight to get it to refresh, then re-select all the results and cmd-I for a total. Up-arrow+ enter works much better, and more quickly.

Comments are closed.