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!
Best Answer
-path "/usr/local/connect/"
would match only on a file path that is exactly/usr/local/connect/
. That will never match because withfind .
, all the paths will start with.
So you'd want:
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: