1

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.

samshers
  • 678

1 Answers1

2

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 53248

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:

pLumo
  • 22,565
  • For directories, that will never be more than 10M - from where is this limitation comming? FS or inode table ... etc? – samshers Sep 02 '20 at 09: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 02 '20 at 09:23
  • I added some links for further reading. – pLumo Sep 02 '20 at 09:54
  • thanks for Further Reading. That is going out of way to help ppl understand deeper :-) – samshers Sep 03 '20 at 05:14