سؤال

How I can make the grep command locate certain words in the files specified by the routes found by the locate command?

locate my.cnf | grep user

(I want that grep command search the word "user" on the files found for locate command)

هل كانت مفيدة؟

المحلول

Instead of a pipe, use command replacement:

grep user `locate my.cnf`

نصائح أخرى

Try:

locate my.cnf | xargs grep user

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

In order to play nice with situations when locate results have spaces in names, you could do this

locate -0 my.cnf | xargs -n1 -0 grep user
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top