I'm learning linux bash on my mac. Is there an equivalent to this command in OSX?
locate --regex 'bin/(bz|gz|zip)'
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.Sign up to join this community
The macOS version of
locate doesn’t have a
regex option. You can use
? in the search pattern but that’s it.
Before you can use
locate you will have to enable it (i. e. have the
locate database built) using the following command—by default it is disabled:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
The default version of
locate on OS X/macOS does not support this, like Tom E. indicated.
Apple ships the BSD version of most of the command-line tools (formerly called "the BSD subsystem").
Therefore there are two answers to your question:
You might construct any number of equivalent command oneliners that accomplish the same as the one command you quoted. For learners, the keywords there are not only regex, but also pipes, backticks and some more.
But to consider your first line of context ("learning linux bash") the following answer may be more appropriate:
Your example might be from a book like "The Linux Command Line: A Complete Introduction". That is problematic to apply word for word or command by command on OS X/macOS. Apple mostly ships BSD tools and (almost?) all of them in very outdated and insecure versions (fanatical GPL3-allergy on Apple's side). Linux ships mostly GNU-tools that might/will have often the same names but differing features/options compared to their BSD equivalents.
macOS can therefore have not only an equivalent, but the exact same command and syntax you gave as an example. But for that you have to install the corresponding GNU tools. In your case above
findutils. That contains the
locate command in the flavour used by your example.
This is generally recommendable if you want to learn "linux bash". Install all GNU tools you might need to follow the examples. This also includes a current bash. Apple ships the horrendously medieval version of
/bin/bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16) Copyright (C) 2007 Free Software Foundation, Inc.
Whereas GNU bash is much newer:
/usr/local/bin/bash --version GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin16.7.0) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
If you want to learn macOS/BSD bash/command line you should get other guides or books.
If you want to stick to your current guides or really learn the GNU/Linux way, then you should install the GNU tools.
You can use package managers to do this on macOS, just like on other BSDs or linux.