I am trying to exclude folders from being searched in for files. It actually works relatively well.

My code looks like this: find . -type d -regextype posix-extended -regex "(./Scripts/testfolder)" -prune -o -type f -print

My problem is, however, that I would like to exclude all occurences of folder name regardless of path. Basically I want to remove ./Scripts/ part and just ignore testfolder folder, wherever it is. Can it be done by improving the regular expression?

When I run: find . -type d -regextype posix-extended -regex "(testfolder)" -prune -o -type f -print, the folder is entered and files are fetched.


You need to realize that the -name option in find really refers to the basename of the pertinent object being referred to. Hence, we can look up the directory by name and then prune it:

find . -type d -name 'testfolder' -prune -o -type f -print

Not the answer you're looking for? Browse other questions tagged or ask your own question.