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?