Linux – Find files but exclude several directories

bashbash-scriptinglinuxshellUbuntu

How do I use find to list every single file but exclude a handful of directories from the search?

find / -type f -not -path "./foo*" -not -path "/bar*" -print

I've seen examples on other stackexchanges, eg ./, but nothing I've tried seems to work.

This kinda works:

find / -type f -not -path "*foo*" -not -path "*bar*" -print

But not really; it also excludes files named "foo" and "bar" from the search results.

Best Answer

find / -type f -not -path "*foo*/*" -not -path "*bar*/*" -print seems to do the trick.

Related Question