Why does GNU find match files it's told not to? (in a big query)

61 Views Asked by At

I have a GNU find command

find . -type l,f ! -path './bin/ash' <600 more condition like ! -path './bin/mv'> -printf "rm %P\n"

which runs in a directory with a bin/ash file (a symlink).

Problem: find prints rm bin/ash. Why does it do it?

find is supposed to add sequential conditions with -a, not -o. A shorter query works. I checked for paths that break quotation, but there are none.

What has no effect:

  • Switching type query part to \( -type l -o -type f \) .
  • Adding -a between all conditions.
  • Adding or removing ./ to paths.
  • Adding \( \) around the -path condition group or individual conditions.
  • Replacing ! with -not has no effect

Did I run into a bug in GNU find, or am I missing anything?

find (GNU findutils) 4.7.0
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)

Update: MCVE. On my Ubuntu 20.04 box, I do the following:

cd /usr/bin/
find . -type l,f > ~/mcve.txt
FIND_CONDITION=$(cat ~/mcve.txt | xargs printf " ! -path '%s' " | paste -s)
find . -type l,f ${FIND_CONDITION} -printf "rm %P\n"

The last command prints all the 2150 files/symlinks from /usr/bin/.

uname -a: Linux MyHostname 5.8.0-36-generic #40~20.04.1-Ubuntu SMP Wed Jan 6 10:15:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

0

There are 0 best solutions below