bashmacosfind

How Do I Exclude Package Files (Directories) from Bash Mac find?


How do I exclude Mac Package files from the search path of the Bash find command?

The macOS has some "files" that are really unix directories. These are called "packages". A Mac app file is a great example, but there are others. Unfortunately, I don't see any find switches to exclude packages.

Here's a typical find command that does NOT work. It will search inside the .app files:

find /Applications -type f -path ./*.app -prune -o  -print

In this case I want it to list the actual .app files, but NOT search inside of them.

I have tried many variations of this, and none have worked.

Here are some other typical file extensions that are really packages:
.app .pkg .scptd


Solution

  • Insert a regex criterion that returns false for all content within a package directory. Unfortunately, it does mean having to list the file extensions of the package directories whose contents you wish to exclude. I've listed quite a few of them in my regex string:

    find -E /Applications ! -iregex '.*\.(app(download)?|scptd|pkg|bundle|qlgenerator|c?action|dictionary|cannedSearch|photoslibrary)/.+'