linux - What is wrong with my find command usage? -
linux - What is wrong with my find command usage? -
i'm trying find files name matches c++ file extensions exclude directories matching pattern this:
find /home/palchan/code -name "*.[cchh]" -o -name "*.cpp" -o -name "*.hpp" -a ! -name "*pattern*"
and still gives me output files like:
/home/palchan/code/libfox/pattern/hdr/fox/redfox.h
which has pattern in it?
here example:
> ls -r . .: libfox ./libfox: redfox.c redfox.h pattern ./libfox/pattern: redfox.c redfox.h
and run:
> find . \( -name "*.[hc]" -a ! -name "*pattern*" \) ./libfox/pattern/redfox.c ./libfox/pattern/redfox.h ./libfox/redfox.c ./libfox/redfox.h
the next should work:
find /home/palchan/code \( -name "*pattern*" \) -prune -o -type f \( -name "*.[cchh]" -o -name "*.cpp" -o -name "*.hpp" \) -print
from man find
:
-name pattern base of operations of file name (the path leading directories removed) matches shell pattern pattern. metacharacters (`*', `?', , `[]') match `.' @ start of base of operations name (this alter in findutils-4.2.2; see section standards conformance below). ignore directory , files under it, utilize -prune; see illustration in description of -path. braces not recognised beingness special, despite fact shells including bash imbue braces special meaning in shell patterns. filename matching performed utilize of fnmatch(3) library function. don't forget enclose pattern in quotes in order protect expansion shell.
so, basically, should utilize -prune
exclude directories instead of ! -name something
linux bash find
Comments
Post a Comment