Can find return results based on the size of directories?
Below command is working fine as expected -

find * -type f -size +10M -exec ls -hlSr {} \+

But on applying the same to directories its not returning any results

find * -type d -size +10M -exec ls -hlSr {} \+   //no output

So want to know if some variation of above is possible.

I know du can be used like this --> du -hs * | sort -h to achieve desired output but I am more interested in understanding find limitations and usage scenarios.


That is expected.

find -size checks the inode size only (remember, directories are also just "files"), not the directory contents. For directories, that will never be more than 10M, so the find result will simply be empty.

The inode size is the same you get when you run stat:

$ du -s dir
61943836851 dir

$ stat -c %s dir

So it's not possible with find alone.
But you could of course use find . -type d -exec du -hs {} + to be able to use find's filter options.

Further Reading:

  • For directories, that will never be more than 10M - from where is this limitation comming? FS or inode table ... etc? – samshers Sep 2 '20 at 9:18
  • That is just a guess from my side ... directory files do not hold much information and 10M is a lot and very far from that. Maybe if you change your block size to 10M then yes, but I'm not an expert for unusual file systems ;-) – pLumo Sep 2 '20 at 9:23
  • I added some links for further reading. – pLumo Sep 2 '20 at 9:54
  • thanks for Further Reading. That is going out of way to help ppl understand deeper :-) – samshers Sep 3 '20 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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