Im not sure what im doing wrong on this. I've read through a bunch of posts and websites but am still having issues.

I need to check a system for files that have changed in the past day but I need to skip certain mounted folders since they are mounted to drives with tons of TBs.

Here is the setup: I have few drives mounted to folders inside of /usr/local/connect/ /usr/local/connect/logs --> mounts to an NFS /usr/local/connect/DR01 --> mounts to a DR share a few more like this...

I want to run a normal find command (or any command that would work for this) that excludes those directories. Here are somethings i've tried that haven't seemed to work.

find . ! -path "/usr/local/connect/" -type f -name "*.txt" -mtime -1

find . -type f -path "/usr/local/connect/" -prune -o -name "*.txt" -mtime -1

Neither of those seem to work. I've tried to do it in different orders (like -type f first, or prune first in line, etc.) as well. But I read prune removes the proceeding path. This seems like it should be an easy thing to do. Let me know if you see my mistake! Thanks in advance!


-path "/usr/local/connect/" would match only on a file path that is exactly /usr/local/connect/. That will never match because with find ., all the paths will start with .

So you'd want:

find / -path '/usr/local/connect/*' -type d -prune -o \
       -name '*.txt' -type f -mtime -1 -print

The -print is also important. Without it, there would be an implicit -print for files that match the whole expression (so both parts of the -o).

Note that you can also use -xdev to prevent crossing any file system boundary.

If you want to run it with find . when the current directory is /usr/local, that would have to be:

cd /usr/local &&
  find . -path './connect/*' -type d -prune -o \
         -name '*.txt' -type f -mtime -1 -print
  • Oh man -- thanks! All of that helped out so much. Totally forgot about xdev. Why do I have to use the \ at the end of the first line? Is it not possible to use it all on the same line? I have to do it as one command and hit enter and go to the next line and then enter in the new settings? I need to look in to exactly what the -o is. Super helpful! Thank you! – saleetzo May 16 '17 at 23:11

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.