Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .