find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected:

$ find . -iname "*.PDF"
$ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \)
$ find . -path "*_nobackup*" -prune -iname "*.PDF"

They all returned the match:

./folder/file.pdf

:b:

This find returned no matches:

$ find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

I was expecting it to match:

./folder/file.pdf

:confused:

I am running Fedora 25.

What are you trying to filter?

I want a list of all PDF files, excluding file names ending in "_nobackup.pdf" or "_nobackup.PDF", and don't even look in folders ending in "_nobackup".

After -prune there must be -o (or, otherwise) in order to continue with files or non-pruned directories. Then if not a directory and name ends with pdf and name does not have _nobackup then print. The print must be there, otherwise there would be a default print also for the pruned directories.

find . -type d -name "*_nobackup" -prune -o !  -type d -name "*.[Pp][Dd][Ff]" ! -name "*_nobackup.*" -print

Of course -name "*.[Pp][Dd][Ff]" is identical with -iname "*.PDF" , but the latter is not implemented on some Unix find.

1 Like