Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
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
Anybody can ask a question
The best answers are voted up and rise to the top
1 year, 6 months ago
I'm coming from Linux to macOS, and many of my scripts assume GNU versions of the utils provided in
I could just put the GNU coreutils
bin directory in earlier in
Is this commonly done? If I do it, what downsides/breakages should I expect in future?
Dec 4, 2021 at 6:41
Tom Hale Tom Hale
311 2 2 silver badges 8 8 bronze badges
It will break any script which expects BSD-style utilities (different arguments, partially different functionality)
But you can install coreutils with Homebrew or Macports which will give them a g prefix (
gcp etc). And then adapt your scripts to use those (depending on the platform they run).
29.4k 17 17 gold badges 86 86 silver badges 147 147 bronze badges
Dec 4, 2021 at 6:52
nohillside ♦ nohillside
94.6k 40 40 gold badges 201 201 silver badges 247 247 bronze badges
While using un-prefixed coreutils has the potential to break any script expecting BSD-style programs, I have been using un-prefixed coreutils for almost 8 years now, and I've never run into a single issue. Given the anecdotal nature of that experience report you should take it with a grain of salt, but my experience has been that the reported dangers of un-prefixing are overblown.
Dec 4, 2021 at 18:42
I think it's safer to not have the GNU coreutils first in PATH, but I don't really know macOS.
A relatively easy way to get your existing scripts to use GNU coreutils is to
PATH in the beginning of each script.
This way you won't have to rename (or add full path) to all of the commands in a script.
Dec 6, 2021 at 8:33
log in to answer this question.
Not the answer you're looking for? Browse other questions tagged
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only
[ $USE_COREUTILS -eq 0 ] && PATH=$PATH:/path/to/coreutils/directory. This is how it would look in
.bashrcanyway. I doubt mac shells are much different. As far as I know, it would work with
.zshrcas well. I haven't tested the code, so you may need to iron out the kinks. Edit: or just use the Homebrew version mentioned below... : )