I created a hard link

$ ln hours.sh hours_link

test it

$ ls -l hours* 
-rw-r--r-- 2 me staff 653 Apr 12  2018 hours.sh
-rw-r--r-- 2 me staff 653 Apr 12  2018 hours_link

remove it with unlink

$ unlink hours_link
$ ls -l hours* 
-rw-r--r-- 1 me staff 653 Apr 12  2018 hours.sh

so far so good, but unlink can delete the original file which is not a link

$ cp hours.sh hours.bak.sh
$ unlink hours.sh
$ ls | grep hours.sh
#not return anything, hours.sh is deleted

check the manual and very surprised

   unlink - call the unlink function to remove the specified file
   rm - remove files or directories

If not just take it for granted, how should I understand this conversion?


Every entry in a directory is a hard-link to the file. Both rm and unlink remove hard-links. A file is deleted when and only when, all hard-links to it are removed and no process has it open.

Therefore there is no difference (in form, just the name) between the original name and the name created with ln.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.