简体   繁体   中英

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.

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. The second one will follow all symbolic links. The rgrep is a shortcut for 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM