On 19 Jul 17:40, Chris G wrote:
On Tue, Jul 19, 2011 at 04:41:56PM +0100, Brett Parker wrote:
On 19 Jul 16:23, Chris G wrote:
On Tue, Jul 19, 2011 at 04:11:47PM +0100, Brett Parker wrote:
On 19 Jul 15:37, Chris G wrote:
I.e. if I have a file I own that is read only I *can't* delete it if I am the user that owns the file, even using 'rm -f', however if I sudo to root privileges then 'rm -f' will remove the file even if there is no write permission.
Can you delete the single file? If not, then, erm, dya wanna check what the *directory* permissions are, because if the user hasn't got write to the directory, they can't delete things.
Also, please check which rm is being called in each case: as user: which rm as root: which rm
If the output of those don't match, that'll be the problem, probably.
(certainly I, as a normal user, can happily rm -rf my files and directories)
Partly finger trouble on my part:-
I *can* remove read only files that I own using 'rm -f':-
chris$ ls -al total 16 drwxr-xr-x 2 chris chris 4096 2011-07-19 17:34 .
^^^^ looky, write perms on the directory, this is *important*.
drwxrwxrwx 29 chris users 12288 2011-07-19 17:33 .. -r--r--r-- 1 chris chris 0 2011-07-19 17:33 xxx -r--r--r-- 1 chris chris 0 2011-07-19 17:33 yyy -r--r--r-- 1 chris chris 0 2011-07-19 17:34 zzz chris$ rm xxx rm: remove write-protected regular empty file `xxx'? n chris$ rm -f xxx chris$ ls -l total 0 -r--r--r-- 1 chris chris 0 2011-07-19 17:33 yyy -r--r--r-- 1 chris chris 0 2011-07-19 17:34 zzz chris$
However, my original problem, 'rm -fr' *doesn't* remove a directory which itself is read only, if I am the user who owns the directory and files but if I get root privileges I can - what happens is as follows:-
chris$ ls -ald fred dr-xr-xr-x 2 chris chris 4096 2011-07-19 17:34 fred
^^^ directory not got write perms, therefore you can't delete the files *in* it, if it can't delete the files in it, it won't remove the directory (for obvious raisens).
The directories need write permission, the files don't.
You can simply do: find fred -type d -exec chmod u+w {} +
Then you'll probably find that it "just works".
chris$ rm -fr fred rm: cannot remove `fred/yyy': Permission denied rm: cannot remove `fred/zzz': Permission denied chris$ sudo -s [sudo] password for chris: root$ rm -fr fred root$ ls fred ls: cannot access fred: No such file or directory
Yes, that's because root has a mostly get out of jail free card, permissions checks generally go "ah, it's root, sod it, yeah - you've got permission to do that", where as a normal user is bound by the usual filesystem rules.
This is *NOT* something special in rm, this is filesystem level. Ergo, it wouldn't be documented in the rm man or info pages.
Hope that clears up why you *can't* do that rm, and that this is *not* a weird behaviour on the part of rm, but a filesystem permissions level not at all weird, maybe slightly unexpected side effect of the directory not having write support.
Thanks,