发布时间:2026-07-25阅读(1)
首先说一下find命令和grep命令的区别:

找文件内容含指定词的三种方法
方法1: 使用grep命令grep -lR 人无完人 ./
执行man grep命令可以查到-l和-R的功能:
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.
-R, --dereference-recursive
Read all files under each directory, recursively. Follow all symbolic links, unlike -r.
简言之,-l是用于输出内容含指定词的文件的名称,-R是用于遍历某个路径下的所有文件。
记住命令选项-lR的窍门:
# 旧版find命令find ./ -type f -exec grep -l "人无完人" {} \;# 新版find命令find ./ -type f -exec grep -l "人无完人" {}
find ./ -type f -print0 | xargs -0 grep -l 人无完人
Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图