Quantcast
Channel: Does rm -rf follow symbolic links? - Super User
Viewing all articles
Browse latest Browse all 4

Answer by Susam Pal for Does rm -rf follow symbolic links?

$
0
0

Example 1: Deleting a directory containing a soft link to another directory.

susam@nifty:~/so$ mkdir foo barsusam@nifty:~/so$ touch bar/a.txtsusam@nifty:~/so$ ln -s /home/susam/so/bar/ foo/bazsusam@nifty:~/so$ tree.├── bar│  └── a.txt└── foo└── baz -> /home/susam/so/bar/3 directories, 1 filesusam@nifty:~/so$ rm -r foosusam@nifty:~/so$ tree.└── bar└── a.txt1 directory, 1 filesusam@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 bazsusam@nifty:~/so$ tree.├── bar│  └── a.txt└── baz -> /home/susam/so/bar2 directories, 1 filesusam@nifty:~/so$ rm -r bazsusam@nifty:~/so$ tree.└── bar└── a.txt1 directory, 1 filesusam@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 bazsusam@nifty:~/so$ tree.├── bar│  └── a.txt└── baz -> /home/susam/so/bar2 directories, 1 filesusam@nifty:~/so$ rm -r baz/rm: cannot remove 'baz/': Not a directorysusam@nifty:~/so$ tree.├── bar└── baz -> /home/susam/so/bar2 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.


Viewing all articles
Browse latest Browse all 4

Trending Articles