roedie.nl Hmz…

2Jul/071

Unix suprise

Note to self: If a file has read only rights, and you are the owner, you can still delete it. It cought me by suprise...

Filed under: Linux Leave a comment
Comments (1) Trackbacks (0)
  1. The ability to delete a file has nothing to do with the file’s permissions or ownership, but rather the permissions of the *directory* containing it. Everyone gets surprised by that at some point during their learning curve… It’s made worse by the fact that on some systems rm(1) will ask if you want to delete a file that has read-only permissions, encouraging the false belief that it’s the file’s permissions that matter.

    This might be easier to visualize if you no longer think of deletion as deletion. When you do ‘rm filename’, you are not actually deleting a file, you are unlinking it from a directory. That’s why you need write permission on the directory in order to unlink a file in that directory. The file may still be (hard-)linked into other directories, in which case it still exists: hence ‘rm’ does not mean ‘delete’. And actually, even when its last link is removed, the bytes making up the file still exist, somewhere on the disk (but now no-one knows where), until such time as they happen to get overwritten by some other file.


Leave a comment

(required)

No trackbacks yet.