Remove symbol link

command linesymlinkterminal

In terminal, I have made a symbol link like following:

ln -s ../../../../ jni/prod

It symbol links prod directory (which is 4 levels up from current location) to jni/prod .

I'd like to emphasize that it symbol links a directory NOT a file.

Now, I want to remove this symlink, how to do it?

Best Answer

If you find yourself confused about where a file really exists, cd to the directory you expect and use rm -i and refrain from adding any path - delete the file in the current directory. Also, in unix, everything is a file - including a directory. You do have saving grace that trying to delete a file that looks like a directory will pause unless you are recursively deleting files.

Worst case, you could use ls -lai to inspect the inode numbers to be sure a file is really symlinked and not hard linked.

If that doesn't help, make a temp directory and play with links:

touch foo
ln foo bar       # hard link
ln -s foo baz    # sym link
ls -lai
rm foo
ls -lai

At this point, you have the hard link file bar left and a sym link to the missing "foo" file. Since in your case, the link is in a different directory than the target, you shouldn't have too much problem deleting the item you wish.