Use the grep command and find

How can I get the grep command to find specific words in the files specified in the routes found by the locate command?

locate my.cnf | grep user 

(I want the grep command to look for the word "user" in the files found for the locate command)

+6
source share
4 answers

Instead of a channel, use command substitution:

 grep user `locate my.cnf` 
+10
source

Try:

 locate my.cnf | xargs grep user 
+10
source

Probably grep user $(locate my.cnf) is what you are looking for if I understand your question correctly.

0
source

To play well with situations where there are spaces in names in the search results, you can do this

 locate -0 my.cnf | xargs -n1 -0 grep user 
0
source

Source: https://habr.com/ru/post/925041/


All Articles