Search code examples
command-linefilebatch-file

Deleting empty (zero-byte) files


What's the easiest/best way to find and remove empty (zero-byte) files using only tools native to Mac OS X?


Solution

  • Easy enough:

    find . -type f -size 0 -exec rm -f '{}' +
    

    To ignore any file having xattr content (assuming the MacOS find implementation):

    find . -type f -size 0 '!' -xattr -exec rm -f '{}' +
    

    That said, note that many xattrs are not particularly useful (for example, com.apple.quarantine exists on all downloaded files).