0

tl:dr I am trying to get find to completely ignore a specific subdirectory regardless of depth.

I am asking this question in reference to a line of code from maldets open source. It is the find command that generates the filelist that the scanner is to examine. I know find will start at whatever dir specified, at a given maxdepth value.

Is it possible to change the maxdepth level at say dir/subdir/Thisleveldir so that when using the flag -D search nothing below Thisleveldir/ is listed?

For instance I want to search the /home directory to a max depth of 15

find /home -maxdepth 15 -type f -size +100M

until the pwd is /home/user/ReallyHugeDirThatDoesntNeedToBeSearched/ at which point -maxdepth gets set to 1 then once the pwd again is not that specific subdirectory -maxdepth reverts to its previous value of 15.

Is this possible?

  • So [this](http://stackoverflow.com/a/4210072/3076724)? It's not possible to specify `-maxdepth` more than once. – Reinstate Monica Please Feb 25 '15 at 00:26
  • Kind of, but if you use the -D search flag it shows that find will still traverse the directory to be ignored. Same thing with -no -path. They just won't gather and report anything from those directories. I'm trying to find a way to keep find from traversing the directory all together. – Daniel Whitlock Feb 26 '15 at 02:10
  • `find` doesn't traverse that directory. If you do `find -path './whatever_dir' -prune`, there's an implied `-print`, i.e. `find \( -path './whatever_dir' -prune \) -print` and since `-prune` is always true that directory still gets printed (but it does not get traversed). If you want to not print (or perform some other action), just omit it logically, i.e. `find -path './whatever_dir' -prune -o -print` (since the right side has an action, `find` does not append an implied action) – Reinstate Monica Please Feb 26 '15 at 23:53

0 Answers0