File copy tools such as rsync aren't going to help you easily since you don't want to copy any files.
The straightforward approach of listing the files on server A and erasing these files on server B is a good one in most circumstances. It's easier to cope with arbitrary file names if your servers' find
and xargs
commands understand null separators (Linux, *BSD, Cygwin). From A:
cd ./delete
find . ! -type d -print0 | ssh B 'cd /path/to/stuff && xargs -0 rm -f'
This may leave some empty directories behind. You can delete all empty directories (even the ones that were empty before) with
ssh B 'cd /path/to/stuff && find . -depth -type d -exec rmdir {} + 2>/dev/null'
If you only want to remove directories that existed on the source side, you'll need to use the list again:
find . -depth -type d -print0 | ssh B 'cd /path/to/stuff && xargs -0 rmdir'
If there are directory trees on A that contain a lot of files and don't exist on B, this transfers the whole list of files to erase where a well-chosen rm -rf
on B would do the same work locally on B but would save a lot of bandwidth in the transfer. This is the kind of situation where a file synchronization tool would fare well. You could run rsync -nv
and try to parse the output, but it isn't easy to build something reliable on this.