illegal option on macOS (date -d, readlink -f, grep -P) macOS Origin: Platform & cloud OSI layer 7 · Application Last updated 5 Nov 2026

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.

Exact message you may see 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
Seen on: macOS Linux

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 of date -v (BSD)
  • readlink -f
  • grep -P PCRE
  • xargs -r, sort -V, ls --color differences
  • Script copied from Linux

⚡ Quick fix

  1. brew install coreutils and use gdate, greadlink -f
  2. Replace with portable alternatives (python3 -c, perl)
  3. Put GNU tools first in PATH: $(brew --prefix)/opt/coreutils/libexec/gnubin

Detailed fix by platform

macOS

  1. date -v-1d +%F (BSD) vs date -d yesterday +%F (GNU)

How to diagnose

  1. Tool — BSD or GNU?
  2. Flag — GNU-only?
  3. 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:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

command not found — bash: command not found (Linux)command not foundHomebrew Cask: It seems there is already an App at — Homebrew: Error: It seems there is already an App at '/Applications/Chrome.app' (macOS)Homebrew Cask: It see…Homebrew: No available formula with the name — Homebrew: Error: No available formula with the name "x". Did you mean ...? (macOS)Homebrew: No availabl…sed: 1: invalid command code (BSD sed) — macOS: sed: 1: "file.txt": invalid command code f / extra characters at the end of p command (macOS)sed: 1: invalid comma…Your Command Line Tools are too outdated — Homebrew: Error: Your Command Line Tools (CLT) are too outdated. Update them from Software Update / Please update to the latest macOS (macOS)Your Command Line Too…zsh: bad CPU type in executable — macOS (Apple Silicon): zsh: bad CPU type in executable: ./tool (macOS)zsh: bad CPU type in …zsh: command not found: brew — macOS: zsh: command not found: brew (Homebrew not on PATH on Apple Silicon) (macOS)zsh: command not foun…illegal o…

Explore the map of this error Full error map →

🧠 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.