Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
up vote 2 down vote accepted

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.

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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