I just discovered that rm -f can not remove files from a tree including read-only directories. Is there an alternative command that can do this? The removal is triggered by rnapshot and I thought about providing a different value for "cmd_rm".

The background: I'm using rnapshot which emits lots of errors "permission denied" when removing the folder _delete.XXXXX. The errors occur exactly on files in read-only directories. These directory were created automatically by git-annex, so I can not simply give them write permissions.


Set up two files with different write-permissions in a read-only directory:

$ mkdir mydir
$ touch mydir/test1
$ touch mydir/test2
$ chmod a-w mydir/test1 
$ chmod a-w mydir/

Try to remove the stuff:

$ rm -r mydir/
rm: descend into write-protected directory ‘mydir’? y
rm: remove write-protected regular empty file ‘mydir/test1’? y
rm: cannot remove ‘mydir/test1’: Permission denied
rm: cannot remove ‘mydir/test2’: Permission denied

I can not even remove the files directly:

$ rm -rf mydir/test2
rm: cannot remove ‘mydir/test2’: Permission denied

Searching for the read-only directories and making them writable before removal works:

(find /path/to/remove -type d -not -writable | xargs chmod u+w) && rm -rf /path/to/remove

But the command seems really involved for a rather simple task. It this really the only solution? An how can I tell rsnapshot to do such a thing?


I cannot comment so I am writing here.

As far as I know read only means read only - period. Not read write.

I guess you would have to mount your directory read write.

| improve this answer | |
  • The filesystem mount is read-write. It is just some directory deeply in a tree which are read-only. – Erwin411 Oct 24 '14 at 9:26
  • in that case, check out this – adgelbfish Oct 24 '14 at 9:31
  • I don't have the option to change anything in the filesystem. The question is not about nested filesystems but a simple directory tree(a copy of my home directory). – Erwin411 Oct 24 '14 at 9:50
  • then read only is read only. – adgelbfish Oct 24 '14 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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