Size of file and directory

Hello. I do have a problem.
The statement sounds like this: Given a directory, find all subdirectories (regardless of depth) which contain a file that has more than a half of the size of the respective subdirectory.

I've tried to solve this in many ways, but all I came up with is half solutions.

One would be trying this:

find folder -type f -size +x

where I would search for the size of each file, x being a variable, but this should be applied to each file.

Another one, which seems not to work, would be this:

for i in $(ls $1); do 
if [ -d $i ]; then 
echo $i; 
fi; 
done

but still, i should search for each file and compare it with the directory.

trying

ls -R folder

would be a solution, but I can't connect it with another command.

or this one:

for i in `find $1 type -d'
do
        for j in `find $i type -f -size +(size($i))` // in blocks
         do
                echo j;
         done
done

where, size($i) would be the size converted in blocks, and I didn't know how to do that.

Thanks

It is great to see your question, i would greatly appreciate it.

Here is the answer for you.

ls -lh
total 28K
-rw------- 1 thegeek learner  18K Oct 10 05:52 feed
-rw------- 1 thegeek learner 2.5K Oct 10 05:51 feedbacks
-rw------- 1 thegeek learner   32 Oct 10 05:51 tttt

So only the feed is the file whose size is 18k which is more than the half of the dir size which is 28K.

To get that, following is the script.,

for i in `find . -type d`
do 
    echo $i
    dirsize=`du -s $i | cut -f1`
    echo $dirsize
    find $i -size +$dirsize -type f
done

If it requires a little edit for your requirement, go a head and do it. But this would help you in achieving the core part of what you would want.