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.

I used the following command to create a hard link to an executable:

ln `which xcrun` gcc

The link worked as expected. However, it seems I don't have the permissions to remove it.

$ rm gcc
override rwxr-xr-x  root/wheel compressed for gcc? y
rm: gcc: Permission denied
$ unlink gcc
unlink: gcc: Permission denied

Uh oh.

$ ls -l gcc
-rwxr-xr-x  3 root  wheel  1172 May 10  2012 gcc

I don't have sudo access. What do I have to do to delete the hard link?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Do an ls -ld . of the directory containing the hard link. If you own the directory (or have 'w' permission) you should be able to delete it. If the directory (i.e. /tmp) has the 't' (sticky bit) set, then you will be unable to delete this link as you are not the owner of the file. Next time use ln -s (a symbolic link). ACLs might also prevent you from file removal.

share|improve this answer
    
Indeed, the folder does have the sticky bit set (and I don't have the permissions to unset it). That means I have to seek administrator intervention, right? –  Maxpm Dec 20 '12 at 20:08
1  
Unfortunately, yes you do. –  mdpc Dec 20 '12 at 20:08

The hard link is created with original permissions because otherwise anyone could give himself editing permissions to any file.

You need write permissions to the parent folder to be able to remove the file. Make sure there are no ACLs (ls -e) preventing you from doing that.

share|improve this answer
1  
Actually, it's not that the link is "created with original permissions", it's that the permissions are attached to the file itself (inode), and not to the link. You can't have different hard links with different permissions pointing to the same file. –  David Gelhar Oct 21 '13 at 17:06

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.