3

When I want to reverse grep the words in macOS 13.2 like this:

$ sudo find / -name "libpq.dylib" | grep -v "Operation not permitted"
find: /Library/Application Support/com.apple.TCC: Operation not permitted

The result still contains Operation not permitted result. Why didn't the reverse grep work as expected? What should I do to reverse grep the words?

1
  • 1
    Side note: You seem to be traversing the entire file system root /. However, since you're looking for a dylib, I suggest try most likely places such as /usr, /Applications, /System/Applications, /System/Library, and /Library. And /opt/local if MacPorts is installed.
    – DannyNiu
    Apr 25, 2023 at 12:05

2 Answers 2

22

find (like most Unix utilities) sends errors to stderr, the pipe listens on stdout only though. So you need to redirect stderr to stdout to make it work.

sudo find / -name 'libpq.dylib' 2>&1 | grep -v 'Operation not permitted'
1
  • This will hide files like foo/Operation not permitted/libpq.dylib though. Unlikely, sure, but not impossible.
    – marcelm
    Apr 26, 2023 at 10:14
9

While the first answer is certainly correct, it may be that what the user really wants is simply to drop all of the stderr from the output, which can be done via

sudo find / -name 'libpq.dylib' 2>/dev/null

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .