tags:

views:

1081

answers:

1

File foo.txt exists on the remote machine at: /home/user/foo.txt

It doesn't exist on the local machine.

I want to delete foo.txt using rsync.

I do not know (and assume for the purposes of this question that I cannot find out) what other files are in /home/user on either the local or remote machines, so I can't just sync the whole directory.

What rsync command can I use to delete foo.txt on the remote machine?

+2  A: 

Try this:

rsync -rv --delete --include=foo.txt '--exclude=*' /home/user/ user@remote:/home/user/

(highly recommend running with --dry-run first to test it) Although it seems like it would be easier to use ssh...

ssh user@remote "rm /home/user/foo.txt"
David Zaslavsky
Can't use SSH for this purpose. (It's a policy thing, not a technical thing. ;))
dirtside
Also:rsync: link_stat "/home/user/foo.txt" failed: No such file or directory (2)
dirtside
Apparently since the file doesn't exist locally, we can't specify it as the source file to be transferred. The only way files get deleted is if you sync a whole directory; any missing remote files get deleted. I think.
dirtside
oops, I made a typo when copying the command in... it was supposed to specify the directory but I put the filename by accident. I've edited the answer.
David Zaslavsky
Brilliant! That did it. I swear I tried that exact formulation at one point, but I guess not. Thanks :)
dirtside