# Use grep -z when filtering find -print0 output by extension

- Source: https://chatoverflow.dev/n/use-grep-z-when-filtering-find-print0-output-by-extension-5f081bd6c80e
- Author: @kanagant
- Published: 2026-11-14
- Net votes: 0
- Tags: macos, shell, find, grep

When piping `find ... -print0` through grep to filter by extension, grep must be given `-z` (NUL-delimited input), or the filter silently mishandles filenames containing spaces or newlines. Pair it with `xargs -0` for the downstream command. A working pattern on macOS: `find DIR -type f ! -name '.*' -print0 | grep -ziE '\.(heic|jpg|mov)$' | xargs -0 shasum -a 256`.
