Deleting Symbolic Links (symlinks)

I recently create a few symlinks in my user folder to point to my music/pictures/movies folders that were on a different volume. While testing, I created multiple symlinks, some of which I moved to the trash.


Will emptying the trash also delete all the files that the symlinks reference?


The reason I ask is because upon choosing to securely empty trash, it began calculating and went well over 4,000 files. I do not have near 4,000 files in my trash, so my only explanation was that the symlinks may be causing the music/pictures/movies that are stored on my seperate volume to be deleted.


Any suggestions would be appreciated.

Posted on Nov 1, 2011 12:52 AM

Reply
7 replies

Nov 1, 2011 6:05 AM in response to brendo234

You should remove a symlink either in the Terminal or using whatever utility you used to create the symlink.

The Finder does not know about symlinks, so it just sees that it looks like a directory and proceeds to walk the directory tree looking for all the files it needs to delete before it can delete the top item (your symlink).


From the terminal it would be


rm /path/to/your/symlink


No other options should be included, and it should only remove the link.


IF AND ONLY IF, the symlink is in a privileged directory and you get a permission error trying to remote the symlink, then you can try


sudo rm /path/to/your/symlink


The password prompt will be for your admin password. You will not see the password echoed, just type it and hit 'return' taking it on faith that you are entering your admin password.

Nov 1, 2011 6:10 AM in response to brendo234

Oh yea, there is a good chance the symlink is currently in a .Trash folder. You can open the Trash find the symlink and move it back to a regular folder before trying to delete to make it easier to enter /path/to/your/symlink,


Or you can open the trash folder, then drag the symlink to the Terminal, and that should cause the path to the symlink to be automatically pasted into the terminal, saving you having to type the path yourself.

Nov 1, 2011 7:50 AM in response to Linc Davis

I would not trust the Finder to not delete all the files. If the Finder was counting up all the files under the symlink, there is a good chance it is going to do a depth first delete before even looking at the symlink.


From a Finder point of view, unless it does an lstat() on the symlink, it is going to look like a directory, and that would tell the Finder it needs to delete everything under the directory before deleting the directory, which just happens to be a symlink pretending to be a directory.

Nov 1, 2011 9:43 AM in response to brendo234

The Finder handles symbolic links just fine. It treats them as if they were aliases. Deleting a symbolic link in the trash does not delete the original files.


The question I have is, why are you using Secure Empty Trash? It's hard to imagine a valid reason for securely erasing a symbolic link the just points to files you want to keep. Try just emptying the trash.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Deleting Symbolic Links (symlinks)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.