寻找在命令行上搜索文件中文本的工具
你好 我正在寻找一些在文件 ex 中使用关键字或模式搜索的脚本或程序。 php、html 等并显示该文件在哪里
我使用命令 cat /home/* | grep“关键字” 但我有太多文件夹和文件,这个命令会导致正常运行时间过长:/
我需要这个脚本来查找假网站(paypal、ebay 等)
Hello
I'm looking some script or program that use keywords or pattern search in files ex. php, html, etc and show where is this file
I use command cat /home/* | grep "keyword"
but i have too many folders and files and this command causes big uptime :/
I need this script to find fake websites (paypal, ebay, etc)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你并没有真正说出你正在使用什么操作系统(和外壳)。您可能需要重新标记您的问题以帮助我们解决问题。
因为你提到了
cat | ...
,我假设您使用的是 Unix/Linux 变体,因此这里有一些查看文件的指示。 (bmargulies 解决方案也很好)。grep
是在文件中搜索文本字符串的基本程序。它的用法是(请注意,“搜索目标”包含空格,如果您没有用双引号或单引号将 searchTarget 中的空格括起来,则调试时将出现一个小错误。)
(另请注意,“搜索目标”可以使用各种通配符,例如 .,?,+,,. 等等,这超出了您的问题范围)。 ...无论如何...
正如我猜您已经发现的那样,即使使用通配符文件名扩展,您一次也只能将这么多文件塞入命令行中。 Unix/linux 几乎总是有一个实用程序可以帮助解决这一问题,
有人会很乐意提醒您,如果您的文件名包含空格字符或换行符,则需要进一步增强。
根据您使用的操作系统的不同,grep 的可用选项可能会有很大差异。如果幸运的话,您可以输入以下内容来获取本地 grep 的手册页。
如果您没有设置大尺寸的页面缓冲区,则可能需要这样做
才能看到“文档”的顶部。按任意键可前进到下一页,当您到达文档末尾时,按最后一个键将返回到命令提示符。
大多数 grep 具有的一些可能对您有用的选项
还有 fgrep,通常被解释为“文件”grep
因为你可以给它一个要扫描的搜索目标文件,并且使用起来就像
最终解决方案
你可以制作一个 srchFile,如
paypal.fake.com
eBay.fake.com
etc.fake.com
然后结合上面的内容,运行以下命令
一些 grep 要求
-fsrchFile
一起运行。现在您正在查找以 /home 开头的所有文件,并使用 fgrep 在所有文件中搜索 paypay、ebay 等。 -l 表示它只会打印找到匹配项的文件名。您可以删除 -l,然后您将看到找到的内容的输出,前面带有文件名。
IHTH。
You don't really say what OS (and shell) you are using. You might want to retag your question to help us out.
Because you mention
cat | ...
, I am assuming you are using a Unix/Linux variant, so here are some pointers for looking at files. (bmargulies solution is good too).grep
is the basic program for searching files for text strings. Its usage is(Note that 'search target' contains a space, if you don't surround spaces in your searchTarget with double or single quotes, you will have a minor error to debug.)
(Also note that 'search target' can use a wide range of wild-card characters, like .,?,+,,., and many more, that is beyond the scope of your question). ... anyway ...
As I guess you have discovered, you can only cram so many files at a time into the comand-line, even when using wild-card filename expansion. Unix/linux almost always have a utiltiyt that can help with that,
This, as one person will be happy to remind you, will require further enhancements if your filenames contain whitespace characters or newlines.
The options available for grep can vary wildly based on which OS you are using. If you're lucky, you type the following to get the man page for your local grep.
If you don't have your page buffer setup for a large size, you might need to do
so you can see the top of the 'document'. Press any key to advance to the next page and when you are at the end of the document, the last key press returns you to the command prompt.
Some options that most greps have that might be useful to you are
There is also fgrep, which is usually interpretted to mean 'file' grep
becuase you can give it a file of search targets to scan for, and is used like
Final solution
you can make a srchFile like
paypal.fake.com
ebay.fake.com
etc.fake.com
and then combined with above, run the following
Some greps require that the
-fsrchFile
be run together.Now you are finding all files starting /home, searching with fgrep for paypay, ebay, etc in all files. The -l says it will ONLY print the filename where a match is found. You can remove the -l and then you will see the output of what is found, prepended with the filename.
IHTH.