linux find command -- need to filter "no such file or directory" messages without redirecting stderr

1.7k Views Asked by At

Essentially I am trying to avoid having this happen without using the 2>/dev/null, is there a way? I would like the output of the chown -c i have linked to it.

ex: find / -user fred -exec chown -c joe {} \;

I would like this to output "changed ownership of '{filename}' from fred to joe" chown -c provides for this functionality but I can't get the output if I have to redirect the whole thing to avoid find's errors!

Thanks for any advice!

1

There are 1 best solutions below

0
On BEST ANSWER

Use process substitution:

find / -user fred -exec chown -c joe {} \; \
    2> >(grep -v 'no such file or directory' >&2)

2> redirects stderr; >(...) reads the redirected stderr, grep -v removes the unwanted lines, and >&2 returns the remaining lines back to stderr