Shell脚本,用于在目录及其子目录中的文件内容中搜索用户给出的文本字符串 [英] shell script that searches the file contents in a directory and its subdirectories for a text string given by the user
本文介绍了Shell脚本,用于在目录及其子目录中的文件内容中搜索用户给出的文本字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个Shell脚本,该脚本在目录及其子目录中的文件内容中搜索用户给出的文本字符串.它列出了具有给定字符串的所有此类文件名,并将其存储在临时文件"abc"中.
问候,
Hi,
I want to write a shell script that searches the file contents in a directory and its subdirectories for a text string given by the user. It list all such file names having the given string and the store in a temp file "abc".
Regards,
推荐答案
使用find
[ ^ ]命令与grep
[ ^ ].自编写find
脚本以来已有很长时间了,因此我无法提出一个示例,但这将是这样的:
Using thefind
[^] command combined withgrep
[^] should do it. It''s a long time since I wrotefind
scripts so I cannot come up with a sample off the top of my head, but it will be something like:
find . -name -exec grep "pattern" {} \;
[edit]
添加了我认为有必要的-name
.
[/edit]
[edit]
added -name
which I think is necessary.
[/edit]
这篇关于Shell脚本,用于在目录及其子目录中的文件内容中搜索用户给出的文本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文