views:

798

answers:

3

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

+1  A: 
find /path/to/stuff -empty

If that's the list of files you're looking for then make the command:

find /path/to/stuff -empty -exec rm {} \;

Be careful! There won't be any way to undo this!

dwc
Better to use + than ; if you have a current find -- that way it acts the way xargs would if it were in the pipeline.
Charles Duffy
+8  A: 

Easy enough:

find . -type f -empty -exec rm -f '{}' +
Charles Duffy
-type fgood call
dwc
I usefind . -size 0 -exec rm {} \;but add -type f should be better
Bank
So, in English, "find all empty files in the current directory and delete them without prompting the user"?
endolith
So how would you do this recursively?
endolith
@endolith - the command already given does recurse; you'd need to use an argument such as `-maxdepth 1` to prevent it from doing so.
Charles Duffy
+1  A: 

Use:

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

with all the other possible variations to limit what gets deleted.

paxdiablo