how to use the unix “find” command to find all the cpp and h files?

后端 未结 6 2090
南笙
南笙 2021-02-01 03:18

I know that to find all the .h files I need to use:

find . -name \"*.h\"

but how to find all the .h AND .cpp

6条回答
  •  野性不改
    2021-02-01 04:12

    A short, clear way to do it with find is:

    find . -regex '.*\.\(cpp\|h\)'
    

    From the man page for -regex: "This is a match on the whole path, not a search." Hence the need to prefix with .* to match the beginning of the path ./dir1/dir2/... before the filename.

提交回复
热议问题