[英]How to find all files on a *NIX server containing a certain string
I want to produce a list of every file on my server that contains a certain email address within the file. 我想生成服务器上每个文件的列表,其中包含文件中的某个电子邮件地址。 Starting with htdocs
and all of its sub-directories. 从htdocs
及其所有子目录开始。
I am using this command: 我正在使用此命令:
find /htdocs/ | xargs grep -n "myname@abc.com"
I seem to be getting the files that contain the string, but I am alos getting a listing of all directories, which I do not want in the list. 我似乎正在获取包含字符串的文件,但是我也无法获取所有目录的列表,而这些目录是我所不希望的。 I simply want the file containg the stirng to be returned. 我只是想返回包含搅拌的文件。
Here are some of the results I do not want to see: 以下是一些我不希望看到的结果:
grep: /htdocs/live/abcdef/contact/facilities/GoogleCalendar/gphp/examples/templates: Is a directory
grep: edited.jpg: No such file or directory
grep: /htdocs/.pki/nssdb: Permission denied
grep
can recurse on a given directory if you use the -r
or -R
flag. 如果使用-r
或-R
标志,则grep
可以在给定目录上递归。 The second one will follow all symbolic links. 第二个将跟随所有符号链接。 The rgrep
is a shortcut for grep -r
. rgrep
是grep -r
的快捷方式。
grep -nsF 'myname@abc.com' -R /htdocs
-F
treats the pattern as a fixed string, and -s
silences the output in case of unreadable or nonexisting files. -F
将模式视为固定字符串,并且-s
在文件不可读或不存在的情况下使输出静音。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.