Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using rsync to copy some source code. The copied code must not be modified at the destination place by my mistake while code editing. So I set --chmod=u-w flag to make it read-only after copying.

 rsync --delete -a --chmod=u-w

First is working well. But from second time rsync cannot perform copying because destination is read-only.

rsync: delete_file: unlink "/path/file1" failed: Permission denied (13)
rsync: delete_file: unlink "/path/file2" failed: Permission denied (13)
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]

I believe there's some feature that forces rsync to overwrite any files regardless of readonly or writable.

How can I do that?

share|improve this question
Can you post the permissions on the files and the directory? – Karlson Sep 25 '12 at 17:15
I think --chmod=u-w will always lock-out rsync from updating files. Why not use --chmod=0755? – emcconville Sep 25 '12 at 20:43
I updated my question. I set u-w because I want to prevent my mistake. – Eonil Sep 26 '12 at 1:42

The copied code must not be modified at the destination place

Wrong: the copied files must be modified at the destination place, when rsync next runs. Unix permissions have no way of expressing “must be modified only by rsync”, unless you run that rsync job as a dedicated user.

Rsync can't delete the files because the directories that contain them are read-only. To avoid this, add the F prefix to apply --chmod only to regular files.

rsync --delete -a --chmod=Fa-w

You might well be better served by not changing the file permissions. If you need to provide read-only access to the files, run the rsync job as a dedicated user, and give other users only read permission to that directory tree (--chmod=go-w might help). Alternatively, expose the directory tree in a read-only view, for example with bindfs (see this answer for a usage example in a different scenario).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.