How can I find every file and directory matching a pattern, excluding one directory using find
?
Say I have the following file structure;
. foo-exclude-me/ foo.txt foo-exclude-me-not/ foo.txt bar/ foo.txt foobar/ bar.txt foofoo.txt
how would I get the following output using find
:
./bar/foo.txt ./bar/foobar ./bar/foobar/foofoo.txt ./foo-exclude-me-not ./foo-exclude-me-not/foo.txt
I have tried using both of the following command:
find . -name 'foo-exclude-me' -prune -o -name 'foo*' find . -name 'foo*' \! -path './foo-exclude-me/*'
but both of them return this:
./bar/foo.txt
./bar/foobar
./bar/foobar/foofoo.txt
./foo-exclude-me # << this should be excluded
./foo-exclude-me-not
./foo-exclude-me-not/foo.txt
How can I properly exclude the foo-exclude-me
directory?
foo-exclude-me
instead of./foo-exclude-me
. Also try appending-print
at the end of the command. – nopcorn Mar 07 '13 at 17:55-print
andfoo-exclude-me
instead of./foo-exclude-me
. – Tyilo Mar 07 '13 at 18:04