macOS: date: illegal option -- d / readlink: illegal option -- f / grep: invalid option -- P
macOS uses BSD versions of core tools, which lack many GNU flags that Linux scripts rely on.
date: illegal option -- dreadlink: illegal option -- fgrep: invalid option -- Pusage: date [-jnRu] [-I[date|hours|minutes|seconds|ns]] [-f input_fmt]xargs: illegal option -- r Meaning
Use the BSD equivalents (date -v-1d, stat -f, realpath from coreutils) or install GNU tools: brew install coreutils gnu-sed grep findutils (commands prefixed with g: gdate, greadlink, ggrep). For portable scripts avoid GNU-only flags or detect the OS.
Common causes
date -d(GNU) instead ofdate -v(BSD)readlink -fgrep -PPCRExargs -r,sort -V,ls --colordifferences- Script copied from Linux
⚡ Quick fix
brew install coreutilsand usegdate,greadlink -f- Replace with portable alternatives (
python3 -c,perl) - Put GNU tools first in PATH:
$(brew --prefix)/opt/coreutils/libexec/gnubin
Detailed fix by platform
macOS
date -v-1d +%F(BSD) vsdate -d yesterday +%F(GNU)
How to diagnose
- Tool — BSD or GNU?
- Flag — GNU-only?
- Install — coreutils?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in macOS
- is damaged and can’t be opened macOS: “App” is damaged and can’t be opened. You should move it to the Trash.
- Operation not permitted (macOS privacy) macOS: Operation not permitted — Terminal/app lacks Full Disk Access (TCC privacy protection)
- Homebrew: Permission denied @ dir_s_mkdir Homebrew: Error: Permission denied @ dir_s_mkdir - /usr/local/Cellar / /opt/homebrew is not writable
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026