当前位置: 首页 > Linux

在linux上查找所有包含特定文本的文件

时间:2023-04-06 19:55:48 Linux

grep>grep-rnw'/path/to/somewhere/'-e'pattern'-r或者-R是递归的,-n是行号,-w代表匹配整个单词。可以添加-l(小写L)以仅给出匹配文件的文件名。-e是搜索期间使用的模式除了这些,--exclude、--include、--exclude-dir标志可用于高效搜索:仅搜索扩展名为.c或.h的文件>grep--include=\*.{c,h}-rnw'/path/to/somewhere/'-e"pattern"排除搜索所有以.o扩展名结尾的文件:>grep--exclude=\*.o-rnw'/path/to/somewhere/'-e"pattern"对于目录,可以使用--exclude-dir参数排除一个或多个目录。例如,这将排除目录dir1/、dir2/和所有匹配*.dst/的目录>grep--exclude-dir={dir1,dir2,*.dst}-rnw'/path/to/somewhere/'-e"模式"ack>awk"/root/"/etc/passwdfind>find/-typef-execgrep-l"rumenz"{}\;>找到。-名称“*.txt”|xargsgrep-i"rumenz"在~/.bashrc中别名ffind>aliasffindfind/-typef|xargsgrep启动新终端>ffind'rumenz'ack-grep>ack-grep"rumenz"ack>ack-irumenzdoc/*在git仓库中找到>gitgrep"rumenz"原文链接:https://rumenz.com/rumenbiji/...微信公众号:入门