StarTrek18
StarTrek18

Reputation: 323

Find all PHP files in the current folder that contain a string

How could I show names of all PHP files in the current folder that contain the string "Form.new" in a Linux system?

I have tried grep "Form.new" .

Upvotes: 0

Views: 197

Answers (2)

BigSmoke
BigSmoke

Reputation: 433

Assuming that your PHP files have a .php extension, the following will do the trick:

grep "Form\.new" *.php

Like @LaughDonor mentioned, it's good practise to escape the dot; otherwise, dot is interpreted as “any character” by grep. "Form.new" also matches "Form_new", "Form-new", "Form:new", "FormAnew", etc.

Upvotes: 0

arkascha
arkascha

Reputation: 42984

You need to search recursive or using* instead of ., depending of whether you want to search only file right inside that directory or also in deeper levels. So:

grep -r "Form\.new" .

or

grep "Form\.new" *

Upvotes: 1

Related Questions