Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Situation as follows: i do su to root, then i create admin file with

cat > adminfile

then i exit from root issuing exit command

i can see following adminfile options

-rw-r--r-- 1 root root 10 2010-06-16 16:25 adminfile

however, after executing rm adminfile it really gets removed

-rw-r--r-- 1 root   root   10 2010-06-16 16:25 adminfile
reinis@reinis-desktop:~/Test/script$ rm adminfile
rm: remove write-protected regular file `adminfile'?

tada.. file is gone!

As i see it - others have only read permision for that file so they shouldnot be able to remove it.. :/

share|improve this question
add comment

2 Answers

up vote 11 down vote accepted

You have write permission on the directory so you can remove any file from it.

Deleting or creating a file is modifying the directory so you need appropriate permissions on the that, rather than the file itself. If you want to be able to modify the file, you'll need write permissions on the file.

Similarly, you need read permission on a directory before you can see which files are in that directory and then you'll need read permission on the files themselves if you want to see what in each file.

share|improve this answer
    
yap! got it! This is really strange. Can not get it why it is implemented this way. –  0xDEAD BEEF Jun 16 '10 at 13:40
3  
@0xDEAD Think of a directory as a text file that is a list of everything in that folder. If you have write access to it you can delete one of the entries. –  Dan Jun 16 '10 at 14:13
    
MM! What good is setting o+r field on directory, without setting o+x? –  0xDEAD BEEF Jun 16 '10 at 14:14
    
However, if the directory has the sticky bit set, then only the owner of the file can remove it. –  petersohn Jun 16 '10 at 14:35
    
@0xDEAD: A directory with only +r is not very useful. On the other hand, having only +x without +r is used quite often. –  grawity Jun 16 '10 at 16:36
show 2 more comments

The owner of a directory is allowed to delete any files owned by other users.

share|improve this answer
add comment

Your Answer

 
discard

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.