简体   繁体   中英

Use command grep and locate

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)

尝试:

locate my.cnf | xargs grep user

使用命令替换而不是管道:

grep user `locate my.cnf`

如果我正确理解你的问题,可能grep user $(locate my.cnf)就是你要找的东西。

为了在定位结果在名称中包含空格的情况下玩得很好,您可以这样做

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM