In the code below I would expect to see find_examples_out/.t1, find_examples_out/.t2 and find_examples_out/.s1 files printed by the find command but they are excluded for some reason. They show up in the sub directories just fine.
Test script:
#!/bin/csh
# GNU find version 4.1.20
find -version
mkdir find_examples_out
cd find_examples_out
set FILES = (t1 .t1 t2 .t2 s1 .s1)
set DIRS = (.hidden normal notnormal another)
foreach f ( $FILES )
touch $f
end
foreach i ( $DIRS )
mkdir $i
cd $i
foreach f ( $FILES )
touch $f
end
cd ..
end
echo "Files present:"
ls -AR
echo
echo "Give me all files but exclude some paths:"
find . \
\( \
-path "\.?.*" \
-o -path "*normal*" \
\) \
-prune \
-o \
\
\( \
-type f \
\) \
-print
cd ..
rm -rf find_examples_out
Here is the output:
GNU find version 4.1.20
Files present:
.:
another .hidden normal notnormal s1 .s1 t1 .t1 t2 .t2
./another:
s1 .s1 t1 .t1 t2 .t2
./.hidden:
s1 .s1 t1 .t1 t2 .t2
./normal:
s1 .s1 t1 .t1 t2 .t2
./notnormal:
s1 .s1 t1 .t1 t2 .t2
Give me all files but exclude some paths:
./t1
./t2
./s1
./another/t1
./another/.t1
./another/t2
./another/.t2
./another/s1
./another/.s1
What am I missing here?
Unless I’ve overlooked something, the -path switch to find compares the pattern given to the path including the filename.
Ergo, your -path “\.?.*” switch will match the hidden files “.t1” etc.
FWIW: in the version of find that I have (v4.4.2), the argument to -path is a shell pattern, not a regex. However, I use bash and have never used csh, so perhaps that makes a difference too.
EDIT: I tried to add this as a comment, but it keeps destroying the formatting.
You could use this to achieve what (I think) you are trying to achieve: