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:

ADVERTISEMENTS

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
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
1 comment… add one
  • Sarah Northway Sep 18, 2012 @ 22:37

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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.