redhat01
redhat01

Reputation: 135

Concatenate 2 parameters in a find expression

I want to write a command that will display all .c and .cpp files from my computer.

I know that I can use find with -name but how can I concatenate the parms to find both file extensions.

Right now I have:

find -name "*.cpp"

Upvotes: 0

Views: 53

Answers (3)

DonCallisto
DonCallisto

Reputation: 29932

Alternative solution

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

In that way you can avoid multiple -o logic condition (as you requested in HerrSerker answer

Upvotes: 2

yunzen
yunzen

Reputation: 33439

I guess

find -name "*.cpp" -o -name "*.c"

The -o meaning LOGICAL OR

Upvotes: 1

fedorqui
fedorqui

Reputation: 290075

Use an OR expression with the -o symbol:

find . -name "*.c" -o -name "*.cpp"

Depending on your system, you may need to escape the dot \. to avoid it matching any character -> -name "*\.cpp".

Upvotes: 1

Related Questions