Search code examples
bashscripting

How to improve this script to find specific file


I have this one line bash script that does part of what I need, but not quite; so I hope someone can help me figure this out....

The script I have looks into dozens of subdirectories that qualify for what I need: a file named 'name' that contains 8Q:

find ../../devices -type f -name "name" -exec grep -q 8Q {} \; -printf '%h\n'

But I also need it to look for file named 'available_instances' that contains the number 1. There are dozens of these subdirectories, but many of them will contain 0, meaning they cannot be used.

How can I extend this script to do that?

TIA, rick


Solution

  • Use -o for multiple conditions :

    find ../../devices -type f \(\
        -name "name"                -exec grep -q 8Q {} \;\
        -o\
        -name "available_instances" -exec grep -q 1  {} \;\
        \) -printf '%h\n'