Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a folder that contains symlinks

Tags:

If I rm -rf a folder that has soft links in it, will it try to follow those links and delete the corresponding folder, or will it simply unlink them?

I have a copy of my home directory with symbolic links in it, and I'm scared to rm -rf it in case it follows those links and blows up the corresponding folders...

like image 262
user358829 Avatar asked Jun 04 '10 20:06

user358829


1 Answers

Generally speaking, rm doesn't "delete". It "unlinks". This means that references to a file are removed by rm. When the number of references reaches zero, the file will no longer be accessible and in time, the area of disk where it resides will be used for something else.

When you rm a directory, the stuff inside the directory is unlinked. Symbolic links are (sort of like) files with the name of their targets inside them and so they're just removed. To actually figure out what they're pointing to and then unlink the target is special work and so will not be done by a generic tool.

like image 137
Noufal Ibrahim Avatar answered Sep 21 '22 22:09

Noufal Ibrahim