user121196
user121196

Reputation: 30990

remove circular symbolic links

I want to remove circular symbolic links. The issue here is how do I correctly parse out the circular link generated by the find -follow command?

 find /home/ -follow -printf ""
find: File system loop detected; `/home/domain_names_new/biz/2015-04-09_03_44_31/2015-04-09_03_44_31' is part of the same file system loop as `/home/domain_names_new/biz/2015-04-09_03_44_31'.
find: File system loop detected; `/home/domain_names_new/biz/2015-04-09_03_44_31/2015-04-13_03_44_03/2015-04-09_03_44_31' is part of the same file system loop as `/home/domain_names_new/biz/2015-04-09_03_44_31'.
find: File system loop detected; `/home/domain_names_new/biz/2015-04-09_03_44_31/2015-04-13_03_44_03/2015-04-13_03_44_03' is part of the same file system loop as `/home/domain_names_new/biz/2015-04-09_03_44_31/2015-04-13_03_44_03'.

Upvotes: 2

Views: 3113

Answers (2)

Pierrick
Pierrick

Reputation: 56

This is what I'd use to remove the children links using the output of the find follow:

find /home/ -type l -follow -printf "" 2>&1 | grep -i 'system loop' | sed -e "s/.*detected; \`\(.*\)' is part.*/\1/" | xargs rm

first redirect error stream to stdout:

2>&1

then prefilter for those messages that warn about a symlink loop (find calls this a file system loop), in case there are other debug messages from find, e.g. permission denied. In case no line is selected we still exit with return code 0 by checking if the return code of grep was 1.

grep -i 'system loop'

extract the filename between "detected; " and "' is part"

sed -e "s/.*detected; \`\(.*\)' is part.*/\1/" : 

delete the corresponding file

xargs rm

Upvotes: 3

Chris Maes
Chris Maes

Reputation: 37722

it seems like /home/domain_names_new/biz/2015-04-09_03_44_31/2015-04-09_03_44_31 is pointing to its parent folder /home/domain_names_new/biz/2015-04-09_03_44_31 . You can check this using

ls -l /home/domain_names_new/biz/2015-04-09_03_44_31/2015-04-09_03_44_31

NOTE: the two other errors have a similar problem; each time a link pointing to its parent folder.

so you need to remove this link or correct it. There is no "magic" solution; only YOU know where the links should point to, the system cannot know this.

Upvotes: 0

Related Questions