How to Ignore Warnings but Keep Error Messages from ‘Find’ Command

bashfindsymlink

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.

Best Answer

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

Related Question