I have a directory ./src with files. I would like to extract all .c files in it, except those .c files that are in ./src/test. I have tried variants of
find ./src -name "*.c" -and -not -name ./src/test
(inspired from here) but none have succeeded.
What am I doing wrong?
I’d use a
grep -vpost-filter, assuming you don’t have newlines in your paths (spaces will be OK):I think your trouble is that the
-namelooks at the last element of the path only, so a-namewith slashes in it simply doesn’t work.If your version of
findsupports it, using-pathin place of-namemight work:Note the modified operand to
-path.