Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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. –  james Nov 13 '12 at 21:57
Those files "filled with zeroes" are called "sparse files": en.wikipedia.org/wiki/Sparse_file. 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

1 Answer 1

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.

source: http://www.commandlinefu.com/commands/view/8757/find-sparse-files

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.