Linux 查找并删除与目录相关的所有符号链接

Gou*_*ash 4 symlink

所以,我有一些情况,我创建了许多符号链接以试图让它们工作,尝试各种组合......现在我有这个错误:

ls: cannot access /etc/sv/me: Too many levels of symbolic links
Run Code Online (Sandbox Code Playgroud)

/service/ 或 /etc/sv/ 中没有符号链接
我能找到解决此错误的唯一方法是删除与 /service/ 或 /etc/sv/ 相关的所有符号链接,但我什至看不到符号链接?

小智 5

您可以通过一些技巧来识别循环符号链接find,试试这个:

find /path/to/search -type l -a ! \( -xtype b -o -xtype c -o -xtype d -o -xtype p -o -xtype f -o -xtype s -o -xtype l \) 2>/dev/null
Run Code Online (Sandbox Code Playgroud)

这是通过过滤符号链接来实现的,然后排除符号链接的目标类型是任何可能的 inode 类型的任何内容。唯一剩下的是那些find无法确定目标类型的东西,这只发生在循环符号链接(损坏的匹配-xtype l