LINUX 拥有遍历文件夹功能的 查找关键字 文件、文件夹

查找文件:

[ admin]# find . -type f -name "a.txt"
./Downloads/hadoop-2.10.0/a.txt

拥有遍历文件夹功能的 查找关键字 文件、文件夹:

[ admin]# vi a
[ admin]# find /home/admin/ -type f | xargs grep "i like apple"
Binary file /home/admin/.cache/tracker/meta.db matches
Binary file /home/admin/.cache/tracker/meta.db-wal matches
grep: /home/admin/.cache/yelp/WebKitCache/Version: No such file or directory
grep: 14/salt: No such file or directory
grep: /home/admin/Downloads/hadoop-2.10.0/share/hadoop/yarn/webapps/ui2/assets/images/datatables/Sorting: No such file or directory
grep: icons.psd: No such file or directory
/home/admin/a:i like apple  (把包含i like apple 那一行取出, 如果是i like apple too, 这里显示的就是i like apple too)
[ admin]# 
[ admin]# cat ai like applehahahaha
 

 grep:查找指定目录/home/admin及其子目录(如果存在子目录的话)下所有文件中包含字符串"i like apple too"的文件,并打印出该字符串所在行的内容,使用的命令为:

[ admin]# grep -r "i like apple" /home/admin
Binary file /home/admin/.cache/tracker/meta.db matches
/home/admin/a:i like apple too

相关推荐