Skip to content

Instantly share code, notes, and snippets.

@tamakiii
Last active December 27, 2023 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamakiii/89650848a2121bb3c97bb12b569c2d0d to your computer and use it in GitHub Desktop.
Save tamakiii/89650848a2121bb3c97bb12b569c2d0d to your computer and use it in GitHub Desktop.
Use coreutils on macOS

coreutils

The default installed commands, such as date, may not be compatible with general Linux systems.

$ date -d '+10 minutes' +%s
date: illegal option -- d
usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]
            [-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
            [[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]

To resolve this, install coreutils:

brew install coreutils

Next, add the following line to either ~/.zprofile or ~/.bash_profile:

export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"

Afterward, the command should work as expected:

$ date -d '+10 minutes' +%s
1683467946

gnu-sed

brew install gnu-sed
PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"

grep

brew install grep
PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"

find

brew install findutils
PATH="/opt/homebrew/opt/findutils/libexec/gnubin:$PATH"
@tamakiii
Copy link
Author

tamakiii commented Jul 20, 2023

$ which sed
/opt/homebrew/opt/gnu-sed/libexec/gnubin/sed

$ which grep
/opt/homebrew/opt/grep/libexec/gnubin/grep

$ which date
/opt/homebrew/opt/coreutils/libexec/gnubin/date

$ which find
/opt/homebrew/opt/findutils/libexec/gnubin/find

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment