hiding output from find command

when I do the find command from / , there are a lot of directories that I do not have access to and so I get

"find: cannot open ..."

How can I suppress these messages so only what was found is output.

I was thinking on

find / -name 'searchterm' | grep -v find

but this doesnt work

Thanks

If you use SH, then you can direct stderr, which is what is causing your "cannot open.." messages, to /dev/null and suppress it that way ie:

find / -name 'searchterm'   2> /dev/null

that is one way to do it. Thanks.

But just out of curiosity, why does the grep -v not find not work?

if we do

ls -ltr | grep -v find

then all the files containing find will not be shown.

If we do

find / -name 'filename' | grep -v find

then I would expect all lines returned with "find" on them being filtered out.

Why does this not happen?

Thanks.

I believe its because the "find: cannot open ..."

is going to STDERR and

and you are piping the STDOUT to grep -v

That's because only stdout is being piped to grep while stderr is being sent to the terminal. In order to exclude stuff using grep send stderr to the same place as stdout.

find / -name 'filename' 2>&1 | grep -v find

that makes complete sense, thanks