[plug] bash scripting problem

David Buddrige buddrige at wasp.net.au
Fri Aug 8 14:43:28 WST 2003


Hi all, 

I am trying to write a bash script that will give me the size of each of the
directories in a given directory.  However, I only want the size of the 
directories that are at the first level. 

For example, 

if I have the following directories from the current: 


./fred
./fred/smith
./fred/smith/foo
./blog
./blog/oggle
./blog/sims
./dag 

Then, I want to see the size of 

./fred
./blog
./dag 

and their respective subdirectories summed up as a single number. 

I have written this script to do this: 

<script>
for x in `find . -type d | cut -d/ -f2 | sort -u`;
do
{
   du -m $x | grep "^[0-9]" | grep "$x$";
}
done
</script> 

However this script seems to give me a value for each of the subdirectories 
as well.  Can anyone see why this is happening?    I would have thought that 
having 'grep "$x$"' would have taken out anything that wasn't the first 
directory only. 

thanks heaps guys 

David.



More information about the plug mailing list