0

Scenario:

$ tree .
.
├── x1.txt
├── x2.txt
└── x3.txt

0 directories, 3 files

$ find . -name "x1.txt" -prune -o -name "*.txt"
./x1.txt
./x2.txt
./x3.txt

$ find . -name "x1.txt" -prune -o -name "*.txt" -print0
./x2.txt./x3.txt

Here we see that -print0 does affect search results. Confused.

Why does presence of -print0 cause find ... to not print x1.txt?

Why does absence of -print0 cause find ... to print x1.txt?

0

1 Answer 1

1

find’s default action (used whenever no action other than -prune or -quit is specified) is -print; in

find . -name "x1.txt" -prune -o -name "*.txt"

there’s an implied -print in all cases:

find . -name "x1.txt" -prune -print -o -name "*.txt" -print

or more accurately,

find . \( -name "x1.txt" -prune -o -name "*.txt" \) -print

Adding -print0 removes that default, so

find . -name "x1.txt" -prune -o -name "*.txt" -print0

means “if the name matches x1.txt, prune it; otherwise, if it matches *.txt, print it, with a null terminator”.

Not the answer you're looking for? Browse other questions tagged .