0

I'm trying to use the find command to find an excel file. However, I only want the files that DO NOT have "permission denied".

So, I tried the following:

find . -name "excel" | grep "!(permission denied)"

However, this doesn't work. I'm using grep version 4.5.12 on Cygwin. Why doesn't this command work? And, is there an easier way to do this? Ideally, the solution would involve find and grep because I'm very familiar with those commands.

Thanks.

makansij
  • 9,303
  • 37
  • 105
  • 183
  • Error messages are reported on standard error, not standard output, and only standard output goes down the pipe to `grep`. You also need to use `grep -v`; the `!` doesn't do what you want. – Jonathan Leffler Jun 25 '15 at 17:26
  • I see the duplicate. What is the equivalent on Mac OSx terminal? – makansij Jun 27 '15 at 18:12
  • 1
    `find . -name "excel" 2>/dev/null` is easiest; it sends all error messages to `/dev/null` so you won't see permission denied. Failing that, follow the other question — whichever solution you prefer. Which works for you depends on whether you're writing a script for anyone anywhere in the world to use at any time under any circumstances, or whether you're writing for yourself — and whether your `find` supports the relevant options. (BSD `find`, and hence `find` on Mac OS X, does not support `-readable`.) – Jonathan Leffler Jun 27 '15 at 20:54

0 Answers0