purge-empty-dirs and max-file-size confusion

Ian! D. Allen idallen at idallen.ca
Fri Apr 24 13:12:57 GMT 2009

On Fri, Apr 24, 2009 at 10:23:06AM +0200, Paul Slootman wrote:
> I don't think the intention is to actually delete empty directories at
> the receiving end; only to prevent them being created.

I have not yet found out how to prevent empty directories from being
created when using "--max-size" or "--min-size".  As I showed in
my original post to this list, "--prune-empty-dirs" does not do it.
Either the man page is wrong/misleading/incomplete, I am misunderstanding
it badly, or rsync is broken.  I am fully prepared to believe that I
am misunderstanding something and will happly work on a better man page
wording when the truth is revealed to me.  I've supplied a short script
below that you can use to see the problem yourself.

> So once they're created due to perhaps an earlier invocation without
> purge-empty-dirs, you'll have to remove them by hand.

As my script below shows, the destination directory does not even exist.
There is no previously-created content in it at all, and yet rsync
creates empty directories even though I say "--prune-empty-dirs".  Why?
How do I make "--prune-empty-dirs" do what the man page says it does?

#!/bin/sh -u

# start with fresh empy directories for source and destination
rm -rf $tmp1 $tmp2

echo '*** create the source directory with six subdirectories'
for i in 1 2 3 4 5 6 ; do
    mkdir -p $tmp1/dir$i

echo '*** create three small files in dir1 dir2 dir3'
for i in 1 2 3 ; do
    dd bs=1M count=1 if=/dev/zero of=$tmp1/dir$i/smallfile

echo '*** create three big files in dir4 dir5 dir6'
for i in 4 5 6 ; do
    dd bs=1M count=11 if=/dev/zero of=$tmp1/dir$i/BIGFILE

echo '*** rsync should copy only the big files and prune all empty directories'
rsync -ai --min-size 10M --prune-empty-dirs $tmp1 $tmp2

echo '*** "find" should show no empty directories, but there are three - why?'
find $tmp2 -empty

echo '*** replace --min-size with an --exclude and it works fine:'
rm -r $tmp2
rsync -ai --exclude smallfile --prune-empty-dirs $tmp1 $tmp2
find $tmp2 -empty   # shows no output - this is correct and expected

echo "*** Why doesn't --prune-empty-dirs work with --min-size and --max-size?"

rm -r $tmp1 $tmp2

| Ian! D. Allen  -  idallen at idallen.ca  -  Ottawa, Ontario, Canada
| Home Page: http://idallen.com/   Contact Improv: http://contactimprov.ca/
| College professor (Open Source / Linux) via: http://teaching.idallen.com/
| Defend digital freedom:  http://eff.org/  and have fun:  http://fools.ca/

More information about the rsync mailing list