Unix find: multiple file types

前端 未结 7 864
一生所求
一生所求 2020-12-02 15:32

I want to run find -name with multiple file types. Eg.

 find -name *.h,*.cpp

Is this possible?

相关标签:
7条回答
  • 2020-12-02 15:40
    $ find . -name '*.h' -o -name '*.cpp'
    

    To find this information in the man page, type man find and the search for operators by typing /OPERATORS and hit enter.

    The . isn't strictly necessary with GNU find, but is necessary in Unix. The quotes are important in either case, and leaving them out will cause errors if files of those types appear in the current directory.

    On some systems (such as Cygwin), parentheses are necessary to make the set of extensions inclusive:

    $ find . \( -name '*.h' -o -name '*.cpp' \)
    
    0 讨论(0)
  • 2020-12-02 15:42

    That's what I use.I strongly recommend the "-regextype posix-extended" argument.

    find . -type f -iname "*.log" -o -iname "*.gz" 
    find . -type f \( -name "*.gz" -o -name "*.log" \)
    find . -type f -regex '.*\(\.gz\|\.log\)'
    find . -type f -regextype posix-extended -regex '.*.(log|gz)'
    
    0 讨论(0)
  • 2020-12-02 15:43
    find . -name "*.h" -or -name "*.cpp"
    

    works for me.

    0 讨论(0)
  • 2020-12-02 15:53

    Thats what I use

    find . \( -name "*.h" -o -name "*.cpp" \) -print
    
    0 讨论(0)
  • 2020-12-02 15:53
    find . -name '*.h' -o -name '*.cc'`
    

    works for searching files.

    find . \( -name '*.h' -o -name '*.cc' \)`
    

    works for executing commands on them

    find . \( -name '*.h' -o -name '*.cc' \) -exec egrep "#include" {} \; -print | egrep "^\."
    
    0 讨论(0)
  • 2020-12-02 15:57
    find ./ -name *.csv -o \\-name *.txt|xargs grep -i new
    
    0 讨论(0)
提交回复
热议问题