Problem with looping the directories

Hi all,

I have a directory which has many sub-directories. Now, I want to check the space of each dir and redirect the output in a file if space exceeds the limit.

I have already done it, but the way I did is not very good. I just listed the directories and awked the last column to get the directory name. After that, I started a loop with first line of that list and got the space. Is there any good way to check their spaces?

If not clear, please tell me to describe with example.
Thanks in advance!
Deepak

Is this any cleaner?

for m in *; do 
  if test -d $m; then
    size=`du -sk $m | cut -f1`
    if [ $size -gt 1000 ]; then
        echo $m contains $size kB
    fi
  fi
done >results.txt

Will this script check each sub-directories and redirect their size or it will just search for a sub-directory and redirect the size?

It will sum the space used by each directory under your current working directory. It will only report those directories using more than 1 MB (but you can change this by modifying 1000 to something else). All the output goes to results.txt

But I want the output of all sub-directories exceeding space limit, not sum.
The output should be like:

/dir1 = 1050
/dir2 = 2030

Thanks for your interest in my problem.

Just run the script I gave you. I think it will give you what you want. If not, paste the output twice, and in the second copy, show what you would expect. Please use "[code]" tags around the output.