How to use unix find and exclude paths?
I need to exclude Time Machine path /Volumes/somedrive/Backups.backupdb from the results of find
.
I currently use the following code, but it generates massive logs as it finds and includes all files in the Time Machine folder:
do shell script "find -x " & from_path & " -print0 | xargs -0 ls -d -F -P -l -T -a -e -i -o -p -q " & from_path & " > " & to_path user name "name" password "pass" with administrator privileges
I tried some examples from this site but I can't figure it out.
How I can use find and exclude certain paths?
Solution 1:
There's a great answer over on Stack Overflow covering this: Exclude directory from find . command
Essentially, the command to exclude directories from find
is as follows:
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print
From the above example, you should be able to extrapolate excluding a single directory.
A brief explanation:
-type d # type: directories
-path dir1 # your path
-o # "or"
-prune # skip the previous set
-print # print results