6

I'm trying to run a find command, and due to the way the folder is set up, I keep getting the following warnings several times in my script:

find -L ./server/ -type f -printf '%s %p\n' | <rest of really long complicated script>

OUTPUT

find: File system loop detected; ‘./server/~andreas/root’ is part of the same file system loop as ‘./’.
find: File system loop detected; ‘./server/~bob/root’ is part of the same file system loop as ‘./’.
find: File system loop detected; ‘./server/~charles/root’ is part of the same file system loop as ‘./’.
...

I know why I'm getting these messages. Those symbolic links are intentionally placed there for other scripts to use, so I want to safely ignore those warnings in the console output.

How can I prevent find from displaying warnings like "File system loop detected", but still keep all "real" error messages?

I can't just tell find to ignore every directory named root. And find has a -nowarn option, but I can't get it to work no matter where I place it. And so far I haven't found a "log level" option for find.

IQAndreas
  • 10,145
  • 21
  • 59
  • 79
  • 2
    GNU `find` manual about `-nowarn`: "These warnings apply only to the command line usage, not to any conditions that `find` might encounter when it searches directories". The warnings you want to ignore are of the latter type. This is why you "can't get it to work". – Kamil Maciorowski Jan 14 '21 at 23:52

1 Answers1

4

If you're using the bash shell, you can use output redirection to suppress specific error messages by filtering stderr through grep:

find ... 2> >(grep -v "File system loop detected") | ...

This is described in the "Process Substitution" section of the bash manual/man pages: https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html#Process-Substitution

zackse
  • 1,513
  • 9
  • 10
  • Will this interfere with the output from `&1` that is being sent through the pipe? – IQAndreas Jan 15 '21 at 03:20
  • 1
    No, because only stderr (file descriptor #2) is being redirected. stdout will still be sent through the pipe as before. – zackse Jan 15 '21 at 04:41