Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have many files in a folder tree, of which some are filled with zeros and others are real files.

How can I delete files filled with zeros recursively?

share|improve this question
what do you mean by "filled with zeroes"? Are they empty files with zero size, or something else? – ImaginaryRobots Nov 13 '12 at 21:25
I mean dummy files created when we start (something like) torrent download. The files display the final size but when we compress them they show their actual size. I want to separate real downloaded files from dummy files by deleting the dummy files. – user69286 Nov 13 '12 at 21:57
Those files "filled with zeroes" are called "sparse files": I didn't find any way to reliably detect them automatically, as a file may be only "partially" sparse. I think a better way to approach this problem is to have your bittorrent client keep incomplete files in a working directory and move them elsewhere once they are complete. Hope this helps. – roadmr Nov 13 '12 at 22:07

You should be able to identify sparse files by using the find command:

find -type f -printf "%S\t%p\n" 2>/dev/null | awk '{if ($1 < 1.0) print $1 $2}'

You can probably add some more find parameters to look for semi-sparse files, though those will probably depend more on your specific situation.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.