D
D
DVoropaev2018-08-18 13:14:34
linux
DVoropaev, 2018-08-18 13:14:34

How to use the grep command to search for a line only in certain files?

Let's say I want to find a file that has a certain string in it.
I can
grep -r "string" /path
but there are too many files and I know I need a file. ending in .conf
I tried
grep -r "string" /path/*.conf
but it looked for a directory. ending with .conf

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
longclaps, 2018-08-18
@longclaps

--include

S
Saboteur, 2018-08-18
@saboteur_kiev

find -type f -name "/путь/*.conf" | xargs -n 10 grep "строка"

V
Victor Taran, 2018-08-18
@shambler81

find . -regex ".*\.conf" -exec grep -f "тут что ищем" {} \;

you will get the names of the files in which there is a mention of your line
And here is an example if you need to replace
, for example, change one value in all files (the regular expression was written for delbian there are several php.ini)
find . -name 'php.ini' -exec sed -i 's/log_errors = Off/log_errors = On/g' "{}" \;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question