Results 1 to 3 of 3
I have looked at many of the post regarding finding/displaying files by size. Though I have not found anything specific
to directories. I have tried using the same logic for ...
- 07-16-2009 #1Just Joined!
- Join Date
- Jul 2009
- Location
- Toronto, Canada
- Posts
- 2
finding/displaying directories by size
I have looked at many of the post regarding finding/displaying files by size. Though I have not found anything specific
to directories. I have tried using the same logic for files for directories but without much luck.
Here is what I am trying to do.
I have a directory that has 3 levels of subdirectories. I would like to display the 3rd level of subdirectories with
their size but only the ones that are larger than 20MB. Doesn't really matter if I see the 1st and 2nd level directories
as well.
Here is what I have tried:
users# find -maxdepth 3 -type d -size +20M -ls
I get back
users#
(no error message - and I know there are many folders larger than 20MB in this folder)
If I take out the "-size +20M" it returns me all the directories in the first 3 levels.
I also tried using the du command, however there does not seem to be the option for specifying sizes
du --max-depth 3 -h
This gives me a nice display but, again, all the directories.
Any help would be appreciated.
- 07-16-2009 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
The reason the '-size +20M ' option didn't work is because it's checking the size of the directory file itself, not the total amount of space used within the directory.
What I would do is use the 'du' command to determine the space used by a directory and then pipe the output from find to awk to select the directories you want.
Code:find -maxdepth 3 -type d -exec du -sm {} \; | awk '($1 > 20) {print $0}'
- 07-17-2009 #3Just Joined!
- Join Date
- Jul 2009
- Location
- Toronto, Canada
- Posts
- 2
Thank you very much!
That is exactly what I was looking for.


Reply With Quote