Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I delete write-protect file(hard link) in my own directory? [closed]

Tags:

linux

unix

The process is like the following root is a file whose owner is root:

~$ ln root another_file
~$ ls -l another_file
-rw-r--r-- 2 root root 0 Jan 24 15:48 another_file
~$ rm another_file
rm: remove write-protected regular empty file `another_file'? y
~$ ls -l another_file

However, this won't work..

~$ ln root another_file
~$ chmod a+w another_file
chmod: changing permissions of `another_file': Operation not permitted
like image 818
Hanfei Sun Avatar asked Feb 17 '23 18:02

Hanfei Sun


1 Answers

This is one of the unix priciples. It is perfectly all right. The reason simply is that you have write permission to the directory itself. That grants you control over all entries contained in that directory. You'd have a huge problem otherwise. Note that this rule is not limited to hard links, but to every entry in general.

like image 109
arkascha Avatar answered Feb 27 '23 12:02

arkascha