2

I've been experimenting with file permissions and ownership lately, and I tried this:

touch a
sudo chown root:root a
sudo chmod 000 a

I can't read, write, or execute the file, but I can still delete it using -f. Why is this? I don't own the file, and nobody has any permission for the file. Shouldn't you need root to delete a 000 file you don't own?

---------- 1 root  root      0 Apr  3 20:18 a
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
tkbx
  • 10,597
  • 13
  • 35
  • 41

1 Answers1

2

What you call "delete a file" is really just deleting a reference to the file in a directory , and the right to do so is the right to modify the directory; the file permissions play no part in this. If that was the last reference to the file, the file is destroyed, but that is a separate issue.

vonbrand
  • 18,156
  • 2
  • 37
  • 59