17

I'm working on a HP-UX system and I want to find if there are any circular symbolic links.

So far I'm using the command:

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

But it's only doing ls -lrt on current directory as result.

What command should I use to find all circular symbolic links in a system?

voretaq7
  • 80,749
Vladimir
  • 173

1 Answers1

25

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.

DerfK
  • 19,826