[plug] bash scripting problem

Dirk Modrow dirk.modrow at aesltd.com.au
Mon Aug 11 16:25:46 WST 2003


I would add the -h to it ad the end

At 02:56 PM 8/08/2003, you wrote:
>man du
>
>
>--max-depth=N
>print the total for a directory (or file, with --all) only if it
>is   N   or  fewer  levels  below  the  command  line  argument;
>--max-depth=0 is the same as --summarize
>
>
>
>
>On Fri, 2003-08-08 at 14:43, David Buddrige wrote:
> > 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