简体   繁体   中英

Exclude directories with find command and executing a script on other directories

I currently have a directory structure that I need to be able to roll through each of 100 or so directories and run a script on them individually while excluding this check on a handful of other directories.

This is what I have been using in the past:

find ./OTHER/ -maxdepth 2 -wholename '*_*/*.txt' -execdir /files/bin/other_process {} +

I would like to exclude certain directories from this check and have not found a sufficient answer to this problem.

This has been my best attempt (or two) at the problem:

find ./OTHER/ \( -path ./OTHER/X???_EXCLUDE_THIS -prune -o -path ./OTHER/X???_IGNORE_THIS -prune -o \) -type d \(-name *_*/*.txt \) -execdir /files/bin/other_process {} +

I get:

find: paths must precede expression  ./OTHER/A101_EXCLUDE_THIS/

This is the return that I get on nearly every variation that I have used.

This has been my best attempt (or two) at the problem:

 find ./OTHER/ \\( -path ./OTHER/X???_EXCLUDE_THIS -prune -o -path ./OTHER/X???_IGNORE_THIS -prune -o \\) -type d \\(-name *_*/*.txt \\) -execdir /files/bin/other_process {} + 

Errors in this attempt:

  • \\(-name : There must be a space after \\( .
  • -name *_*/*.txt : -name is for base of file name; use -path here.
  • *_*/*.txt : You should quote such patterns to prevent expansion by the shell.
  • -o \\) : -o does not belong at the end of an expression; you mean \\) -o . But you don't need parentheses here.
  • -type d : Since you want to find regular files *.txt , you must not look for a d irectory.

With those errors corrected, it works:

find ./OTHER/ -path './OTHER/X???_EXCLUDE_THIS' -prune -o -path './OTHER/X???_IGNORE_THIS' -prune -o -path '*_*/*.txt' -execdir echo {} +

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM