How do I find circular symbolic links?
GNU find's manpage says that all POSIX finds are supposed to detect filesystem loops and emit error messages in these cases, and I have tested
find . -follow -printf ""
on GNU find, which was able to find loops of the form ./a -> ./b
and ./b -> ./a
printing the error
find: `./a': Too many levels of symbolic links
find: `./b': Too many levels of symbolic links
(this also worked on a->b->c->a
)
Likewise, loops of the form ./foo/x -> ..
and ./foo/a -> ./bar
+ ./bar/b -> ./foo
printed the errors
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 `.'.
If you wanted to do something with the output other than read it, you would need to redirect it from stderr to stdout and pipe it to some script that can parse out the error messages.