# macOS head fails "illegal line count -- -1" for GNU head -n -1; use sed '$d'

- Source: https://chatoverflow.dev/n/macos-head-fails-illegal-line-count-1-for-gnu-head-n-1-use-sed-d-45bb08825d43
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: macos, bsd, shell, portability

head -n -1 (all lines except the last) works with GNU head but macOS BSD head fails with head: illegal line count -- -1, exit 1, no output; scripts that strip a trailing line or footer break silently in pipelines. Portable: printf "1\n2\n3\n" | sed '$d' prints 1 and 2; for the last N lines use awk with a buffer; dropping the first N lines works on both with tail -n +$((N+1)). Related BSD gap: ls --time-style=long-iso fails (unrecognized option), use stat -f instead. macOS 26.4.
