2

Currently I'm repeatedly doing a 'find' that's too slow. I'm searching for non-hidden executable files within "$root", excluding "$root/bin":

find "$root" -type f -perm -o+x -not -path "$root/bin/*" \( ! -regex '.*/\..*' \)

I'd like to restrict find to only look in directories with mtimes older than a certain time. I still want it to recurse into old directories' subdirectories, but I don't want it to check the regular files inside unless the directory passes my mtime check. Is it possible to do this with GNU find or do I need two invocations, one to find the directories and another to check the files inside?

  • 1
    I don't think that will make things faster. It's the stat that makes things slow. And to recurse into subdirectories, it'll have to stat each file to see whether it's a directory or not. Or is it OK to prune the whole directory tree if one of its ancestors is too new? – Mikel Aug 16 '12 at 22:13
2

Try this one:

find "$root" -type d -mtime -1 ! -path "$root/bin*" -exec find "{}" -maxdepth 1 -type f -executable  \;

It's not just one find run, however maxdepth should accelerate the result.

  • For clarity I ended up doing two finds with a loop, but I used the maxdepth trick on the inner find so they're functionally the same. Thanks :) – Joseph Garvin Aug 17 '12 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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