Recursively find all files that match a certain pattern

后端 未结 4 602
旧时难觅i
旧时难觅i 2020-12-13 05:44

I need to find (or more specifically, count) all files that match this pattern:

*/foo/*.doc

Where the first wildcard asterisk includes a variable number of s

4条回答
  •  天涯浪人
    2020-12-13 06:24

    Untested, but try:

    find . -type d -name foo -print | while read d; do echo "$d/*.doc" ; done | wc -l
    

    find all the "foo" directories (at varying depths) (this ignores symlinks, if that's part of the problem you can add them); use shell globbing to find all the ".doc" files, then count them.

提交回复
热议问题