Sometimes I find it useful to be able to search my entire hard drive with the “find” command, but I want to exclude all volumes on external drives. I have a script that I use instead of the “find” command to exclude external volumes.
Since Catalina still scans the script in some duplicate places due to read-only system volume and data volume. So I have had to customize the script to prevent this.
Ideally, I would like a way to specify “exclude external volumes, but include the main hard drive”. This can be achieved by using the -prune sub-command if it was allowed to override it. For example, something like “find ./Volumes -prune –
Because I have not figured out how to do this, I have to crop explicitly for each external volume. And when the volume layout changes, I have to update the script.
Here is the script:
#!/usr/bin/env bash # inspired by https://stackoverflow.com/questions/4210042/exclude-directory-from-find-command Danile C. Sobral # using special syntax to avoid traversing. # However, logic is refactored (will post to that page so see what the reaction is) echo ============================ echo find - from cwd, omitting external volumes date echo Enter sudo password if requested sudo find . -not ( -path ./System/Volumes/Data -prune -o -path ./Volumes/Backup1 -prune -o -path ./Volumes/Backup2 -prune -o -path ./Volumes/FLASH -prune -o -path ./Volumes/SuperDuper Catalina -prune -o -path ./Volumes/SuperDuper Catalina - Data -prune -o -path ./Volumes/SuperDuper Spare -prune -o -path ./Volumes/SuperDuper Spare - Data -prune -o -path ./Volumes/Time Machine 1 -prune -o -path ./Volumes/Time Machine 2 -prune -o -path ./Volumes/Time Machine MBP 1 -prune -o -path ./Volumes/Time Machine MBP 2 -prune -o -path ./Volumes/userland -prune ) -name "$1" -print 2>/dev/null date echo ============================
Note: The above script works, but requires maintenance when the volumes change and to compensate for Catalina read-only and data volume. So I’m looking for a replacement for the find command above which will be generic and appear roughly as follows:
sudo find . -not ( -path ./Volumes -prune -o -path --overrideprune ./Volumes/Macintosh HD ) -name "$1" -print 2>/dev/null
By the way, since it is referenced in the second comment line in the first script above, have a great discussion about the use of the prune command.