0

I was looking for "*.py" files, and exclude both "build" and "bin" directories. I used this command:

find * -path "build" -prune -path "bin" -prune -o -type f \( -name "*.py" \) -print > findpyfiles.txt

The "findpyfiles.txt" still contains results started with "bin/". How to fix it?

Armali
  • 14,228
  • 13
  • 47
  • 141
Troskyvs
  • 5,653
  • 3
  • 23
  • 71
  • 1
    Possible duplicate of [Exclude directory from find . command](http://stackoverflow.com/questions/4210042/exclude-directory-from-find-command) – Bertrand Martel Dec 30 '16 at 02:44
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306) – jww Dec 30 '16 at 08:31

1 Answers1

1

Although the question has an answer elsewhere, it may be worth knowing why your command didn't work right: You omitted an operator between -path "build" -prune and -path "bin" -prune, and -and is assumed where the operator is omitted, thus the -path "bin" is not evaluated when -path "build" returns false. Explicitly specifying the OR operator fixes it, either

find * -path build -prune -o -path bin -prune -o -type f -name "*.py" -print >findpyfiles.txt

or

find * \( -path build -o -path bin \) -prune -o -type f -name "*.py" -print >findpyfiles.txt
Armali
  • 14,228
  • 13
  • 47
  • 141