How 'bout that:
find <dir> -type f -ls | xargs awk 'BEGIN { s=0; } { s += $7; } END { print
s; }'
It sums up the size of all files (-type f) in directory <dir> and all it's
subdirectories.
If you want symlinks counted, add "-follow" to the find statement.
Thomas
Robin Whittle [mailto:[EMAIL PROTECTED]] wrote:
>
> Thanks for this Vincent. You wrote:
>
> > You can get size of your directory by going in the parent directory
> > of the one you want to estimate the size and typing following
> > statement :
> >
> > du -m --max-depth=0 <name of directory>
>
> This gives the disk usage, rather than the total of the file sizes.
> Adding the b option gives the results in bytes, rather than 1024 byte
> blocks, so doing this:
>
> du -mb --max-depth=0 <name of directory>
>
> from the parent directory, or from the directory itself:
>
> du -mb --max-depth=0 .
>
> gives results in bytes - but it is for blocks allocated. So an empty
> directory on my system appears as 4096 bytes. This is a useful
> statistic, but not the main one I want.
>
> [...]
>
> On reflection, I realised that what I really wanted to know
> was how much
> each Maidir (mailbox from my point of view as a user) was taking up in
> the resulting tar.gz backup file.
Well, you can't tell you know how good gzip compresses your user's
Maildir...
> [Other methods tried:]
> tar --totals -c <directory> > /dev/null
> gzip -crv <directory> > /dev/null
I think the above methods are not really what you want - they put heavy load
(either CPU or disk) on your machine when they don't need to.
Ok, here we go - someone correct me when I'm wrong (I don't use courier on
production machines yet...)
> Ideally I would like to know for each Maildirs:
>
> 1 - The number of messages (though I can already find this via the
> client).
Count the number of regular files in the Maildir (eg find Maildir -type f |
wc -l; add -follow to the find statement to follow symlinks)
>
> 2 - The space taken on disc - with the du command.
Yep - including directory size
>
> 3 - The total size of the messages.
See top of msg
>
> 4 - Its size after being tarred and gzipped.
You have to judge yourself. gzip can't tell you without actually gzipping
AFAIK. I frequently do backups using tar/gzip, with different compression
levels for different file types (but mostly -2 or -3 bcecause for me backup
speed is more important for me than saving some 500 kB). Do some test
backups, average the compression results, and use that as a calculatory base
for future backups.
>
> The last one is what I am really concerned with. It can be done with:
>
> tar --totals -cz <directory> | wc -c
>
> This causes tar to pass its output through gzip and then to "wc" word
> count, with the -c option to show only the number of bytes, not lines
> and words.
>
> Or with the du command and more simply, without tar's "Bytes written"
> figure, which only approximates the total size of the files:
>
> du -mb --max-depth=0 <directory>
> tar --totals -cz <directory> | wc -c
>
This, again, puts load on your machine without needs. You said you want to
dry-run your backup, to estimate the size it needs? This way you're doing
your backup twice, but once it's written to /dev/null...
>
> Now, I want to invent a Perl script to do this for all my Maildirs in
> alphabetical order, and create a nice little body of text of
> their name,
> their disk usage in 1024 byte blocks, and their tar-gzipped size, with
> commas for thousands and millions to make it easier for me to read.
> Then, to make it easier to use when my mind is in email mode, rather
> than Linux command line mode, I could set up a Maildrop filter rule to
> look out for an email from myself with a special subject line. That
> rule would run the Perl script and the resulting email would
> contain the
> report on mailbox sizes.
>
> - Robin
>
Have fun,
Thomas
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
courier-users mailing list
[EMAIL PROTECTED]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users