delete files

Brian K. White brian at
Fri Nov 11 16:44:56 MST 2011

On 11/11/2011 5:15 PM, Carlos Carvalho wrote:
> Brian K. White (brian at wrote on 11 November 2011 15:59:
>   >Is there any way to specify a file to be deleted on the remote side
>   >explicitly by name?
>   >
>   >I would have thought that deleting the file locally, the rsyncing the
>   >non-existing file with --del would have resulted in the remote file,
>   >which does exist being deleted.
> No, rsync only deletes when it scans the directory.
> You can get what you want with v3.1 and --delete-missing-args.


For now I almost managed by in my script I detect that either
- the argument does not exist
- the user asked for --delete but the argument is not a directory
("not a directory" is detected by either testing the argument if it 
exists, or if it doesn't exist locally, then just looking at the last 
character of the string to see if it is "/")

Either of those happens and I switch to "delete file mode"
which just means when it comes time to do the rsync, instead of pushing 
a local file or dir out to the remote boxes, I pull the specified 
argument from remote to a throw-away temp dir, with --remove-source-files

The specified files get removed from the remote boxes.

The first box sends the file to the local box but the subsequent boxes 
generally send nothing but the checksums since generally the file would 
be the same on all boxes, so the one pulled down from the first box ends 
up matching all the others. But even when they don't all match the 
delete still works, merely I end up downloading the file to local temp 
extra times.

At the end of the loop the entire local temp directory gets deleted, 
which was already part of the script anyways for some diffs and logs and 
emails generated along the way.

Now it's still not working for directories though. If a developer wants 
to push out or update an entire directory or tree to the remote boxes 
they can and always could, but I haven't yet figured out a way to delete 
an entire directory or tree.

Right now using the initial simple scheme above, the closest is, tell 
the developer to rm -rf the directory locally before hand, then try to 
push the non-existing directory, the script detects that the argument 
doesn't exist (doesn't care if it's a file or not) and switches to 
delete mode and ends up doing rsync -acv --remove-source-files 
remote::module/path/to/dir /tmp/unique

The files inside the remote directory get deleted, but the remote 
directory itself does not get deleted.

I believe there will be some way to get this with the 3.0.7 standing 
feature set, I just haven't got there yet.

Thanks for the pointer to the 3.1 feature. If it works I'll try to 
update all the boxes to 3.1 and just use that. It's not an impossible 
number of boxes but some are getting a few years old and it's getting 
harder to build current software on the older ones. But, I do have rsync 
building fine for all targets at least as of 3.0.7 so I'm probably fine 
there. Gotta love that openSUSE Build Service!


More information about the rsync mailing list