views:

41

answers:

4

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 sym links in it, and I'm scared to rm -rf it in case it follows those links and blows up the corresponding folders...

+1  A: 

just try it... ;) it will simply unlink the softlinks.

Axel
+1  A: 

No. rm -rf won't follow symbolic links - it will simply remove them.

% mkdir a                                                             
% touch a/foo
% mkdir b                                                               
% ln -s a b/a                                                           
% rm -rf b                                                              
%   ls a                                                                  
foo
Jordan Lewis
A: 

It will remove the soft links. main files should be remained.

Ehsan
+1  A: 

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.

Noufal Ibrahim