≡ Menu

Apple OS X: Remove a Symbolic Link (Symlink) Command

How do I remove a symlink under Apple Mac OS X using bash command line option?

Symbolic links refer to a symbolic path indicating the abstract location of another file i.e. symbolic links are files that act as pointers to other files. You can use the rm command to remove a symlink. The syntax is as follows:

rm /path/to/symlink

In this example, I have created the symbolic link using the following command:

ln -s /etc/resolv.conf /tmp/foo
ls -l /tmp/foo

Sample outputs:

lrwxrwxrwx 1 vivek vivek 16 May  5 02:04 /tmp/foo -> /etc/resolv.conf

To delete the symlink called /tmp/foo, enter:

rm /tmp/foo
ls -l /tmp/foo

The rm command will remove the symlink /tmp/foo, but not the file the link is pointing at /etc/resolv.conf:

ls -l /etc/resolv.conf

unlink command

You can also the unlink command to remove directory entries including symlinks:

unlink /path/to/sym/link
unlink /tmp/foo
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 1 comment… add one }
  • Sarah Northway September 18, 2012, 10:37 pm

    Is there some way to recursively replace symlinks with the actual files they link to?

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , , ,