find filename based on file content

:confused: There is a flat file on my system which contains email addreses of people in my company. This file is utilized when sending notifications for various things. However nobody knows where this file is located or what it is named. The only thing we know is the email address of a user who needs to be deleted from this file. Is there a command to search through a file system and return results based on the content of the file? For example, if I wanted to see all filenames and locations where jkoller@jkoller.com was in the file how would I do that? Thanks!!!

Try this command:

find / -type f -exec grep email@host {} /dev/null \;

THANK YOU! THAT WORKED!!:slight_smile:

Hey PxT,

The /dev/null is a nice twist - I'm not sure I understand why/how this works - I would have used a -l option on the grep to list the files. But showing the file & pattern found is nice.

Can you explain what this is doing? Is the behavior related to grep or to the find?

One of the features of grep is that if you specify more than one file to search it will show any matches prefixed by the filename. So I specify /dev/null as a second file to search. It will never match, and will always exist. You could really use any file, but /dev/null is a safe choice.