Example 1: Deleting a directory containing a soft link to another directory.
susam@nifty:~/so$ mkdir foo bar
susam@nifty:~/so$ touch bar/a.txt
susam@nifty:~/so$ ln -s /home/susam/so/bar/ foo/baz
susam@nifty:~/so$ tree
.
├── bar
│ └── a.txt
└── foo
└── baz -> /home/susam/so/bar/
3 directories, 1 file
susam@nifty:~/so$ rm -r foo
susam@nifty:~/so$ tree
.
└── bar
└── a.txt
1 directory, 1 file
susam@nifty:~/so$
So, we see that the target of the soft-link survives.
Example 2: Deleting a soft link to a directory
susam@nifty:~/so$ ln -s /home/susam/so/bar baz
susam@nifty:~/so$ tree
.
├── bar
│ └── a.txt
└── baz -> /home/susam/so/bar
2 directories, 1 file
susam@nifty:~/so$ rm -r baz
susam@nifty:~/so$ tree
.
└── bar
└── a.txt
1 directory, 1 file
susam@nifty:~/so$
Only, the soft link is deleted. The target of the soft-link survives.
Example 3: Attempting to delete the target of a soft-link
susam@nifty:~/so$ ln -s /home/susam/so/bar baz
susam@nifty:~/so$ tree
.
├── bar
│ └── a.txt
└── baz -> /home/susam/so/bar
2 directories, 1 file
susam@nifty:~/so$ rm -r baz/
rm: cannot remove 'baz/': Not a directory
susam@nifty:~/so$ tree
.
├── bar
└── baz -> /home/susam/so/bar
2 directories, 0 files
The file in the target of the symbolic link does not survive.
The above experiments were done on a Debian GNU/Linux 9.0 (stretch) system.
rm -rf somesymlink/
, which is destructive with the trailing/
. If 5% of the readers would've experimented, and such an experiment takes 2.5 minutes, that's 5700 minutes, or 95 hours, or a $6000 contribution to society @ $60/hr. I think we all like SO how it is, let's all ask and answer questions together :3