如何找到循环符号链接?

如何找到循环符号链接?

我正在使用 HP-UX 系统,我想查找是否存在任何循环符号链接。

到目前为止我正在使用以下命令:

ls -lrt  `find ./ -follow -type l`

但其结果只是在当前目录执行 ls -lrt 。

我应该使用什么命令来查找系统中的所有循环符号链接?

答案1

GNU find 的手册页说,所有 POSIX find 都应该检测文件系统循环并在这些情况下发出错误消息,我已经测试过

find . -follow -printf ""

在 GNU find 上,它能够找到以下形式的循环./a -> ./b./b -> ./a打印错误

find: `./a': Too many levels of symbolic links
find: `./b': Too many levels of symbolic links

(这也适用于a->b->c->a

同样,形式为./foo/x -> ..and ./foo/a -> ./bar+的循环./bar/b -> ./foo打印错误

find: File system loop detected; `./foo/a/b' is part of the same file system loop as `./foo'.
find: File system loop detected; `./bar/b/a' is part of the same file system loop as `./bar'.
find: File system loop detected; `./foo/x' is part of the same file system loop as `.'.

如果您想要对输出执行除读取之外的其他操作,则需要将其从 stderr 重定向到 stdout 并将其传送到可以解析错误消息的某个脚本。

相关内容