The find command is not working as expected on my OSX with oh-my-zsh. A few examples:

$ find . -name test
find: .: Invalid argument

$ find
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

$ find --version
find: illegal option -- -
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

$ find version
find: .: Invalid argument

I'm not sure what's happening here cause the same examples work as expected on my Linux machine. Any ideas on how to debug it?

  • That's what I thought at first, but forgot to mention. No, it's not aliased. Result of alias | grep find is afind='ack -il' fd='find . -type d -name' ff='find . -type f -name' – Najki Apr 20 '16 at 19:54
  • What does type find say? – pfnuesel Apr 20 '16 at 20:00
  • @pfnuesel find is /usr/bin/find – Najki Apr 20 '16 at 20:03
  • And it's working in bash? What if you don't load your .zshrc? – pfnuesel Apr 20 '16 at 20:04
  • Interesting. It does work in bash. How would I not load .zshrc while using zsh? – Najki Apr 20 '16 at 20:05

That is because you are trying to use the GNU find, which is default in Linux, but Mac OS X comes with BSD find which has many differences.

To install GNU find you will need Homebrew, pretty easy to install, just follow http://brew.sh/

After that you can install findutils:

brew install findutils

More info and other tools to mimic a Linux environment on your Mac here: https://apple.stackexchange.com/questions/69223/how-to-replace-mac-os-x-utilities-with-gnu-core-utilities

Other option is to read the BSD find man pages and adjust your command. Just run man find, you'll see at the top of the screen "BSD General Commands Manual" confirming that in fact you have BSD find.

  • Installing findutils helped, thanks a lot! – Najki Apr 20 '16 at 20:15
  • @Law29 BSD vs BSD? Did you mean BSD vs GNU? – Najki Apr 22 '16 at 12:33
  • 1
    BSD find has differences wrt GNU find (or rather the contrary), but your answer would be improved if you explained why find . -name test is not valid using BSD find. – Law29 Apr 22 '16 at 17:13
  • @Najki -- yes I meant BSD vs GNU. I haven't looked at the history of find specifically, but generally today's BSD tools have stayed closer to the the 1970s versions, while GNU tools have lots of added bells and whistles (some would say too much, others appreciate, YMMV). – Law29 Apr 22 '16 at 17:18
  • This answer makes no sense. The given command in the question is a standard way of using any find. None of it is specific to GNU find. – Kusalananda Oct 31 '19 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.