Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.