Linux (GNU) vs. Mac (BSD) Command Line Utility Differences
If you switch between Mac and Linux often you notice that certain command line utilities are sometimes slightly different…
For example the date
command on linux:
> date -d "yesterday"
Wed Aug 19 10:41:26 UTC 2020
Outputs the date while on mac:
> date -d "yesterday"
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
Gives the above syntax error. On Mac you would need to write:
date -v -1d
Alternatively you could install coreutils package which will add the
some packages specifically the date
utility under the gdate
command. As this
StackOverflow
answer says you can install other GNU utilities on Mac using Homebrew:
brew install coreutils findutils gnu-tar gnu-sed gawk gnutls gnu-indent gnu-getopt grep
As you use CLI utilities you’ll notice small differences such as with xargs
on mac
the --no-run-if-empty
or -r
flag doesn’t exist because as this StackOverflow
answer says the BSD xargs command doesn’t automatically run even if no args are passed.
See the BSD man(ual) pages and the GNU man(ual) pages. This post gives a good overview and comparison of GNU vs. BSD.