bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Faster way to prune directory?


From: Peng Yu
Subject: Faster way to prune directory?
Date: Wed, 15 Apr 2015 23:04:17 -0500

Hi, The following code shows that -prune when used with -exec can be
very slow. Is there somehow a way to speed this up?

~$ cat main.sh
#!/usr/bin/env bash

tmpdir=$(mktemp -d)

function mkalotdir {
local n=$1
local i
local j
local k
for i in $(seq -w "$n")
do
  for j in $(seq -w "$n")
  do
    for k in $(seq -w "$n")
    do
      echo "$tmpdir/$i/$j/$k"
    done
  done
done | xargs mkdir -p
}

function myfind {
find "$tmpdir" > /dev/null
}

function myfindprune {
find "$tmpdir" -exec $(type -P test) -e {}/.findignore ';' -prune -o
-print > /dev/null
}

mkalotdir 10
echo myfind
time myfind
echo myfindprune
time myfindprune

~$ ./main.sh
myfind

real 0m0.018s
user 0m0.005s
sys 0m0.011s
myfindprune

real 0m5.354s
user 0m1.145s
sys 0m1.539s


-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]