2

This question already has an answer here:

I have a hard drive filled with files, and I need to find a specific file without knowing its name. All I know is that the file contains a list of email addresses. Is there any way I can locate it?

marked as duplicate by saiarcot895, Jacob Vlijm, Pilot6, Eric Carvalho, karel Aug 6 '15 at 8:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • GUI or cli? both are in the dupes above :) – Jacob Vlijm Jul 30 '15 at 14:26
1

You can try using grep -r:

Here is an example where I grepped for the text "listen_address" in any file from my home dir:

aploetz@dockingBay94:~$ grep -r listen_address *
Documents/stackOverFlowAnswer_connectToCassandra.txt~:If you are connecting to Cassandra from your localhost only (a sandbox machine), then you can set the `listen_address` in your cassandra.yaml:
Documents/stackOverFlowAnswer_connectToCassandra.txt~:    listen_address: localhost
Documents/stackOverFlowAnswer_connectToCassandra.txt:If you are connecting to Cassandra from your localhost only (a sandbox machine), then you can set the `listen_address` in your cassandra.yaml:
Documents/stackOverFlowAnswer_connectToCassandra.txt:    listen_address: localhost
Documents/stackOverFlowAnswer_connectToCassandra.txt:    listen_address: dockingBay94
Ubuntu One/cassandraClass/cassandra.yaml:listen_address: $(HOSTNAME)
Ubuntu One/cassandraClass/cassandra.yaml:# Leaving this blank will set it to the same value as listen_address
  • 2
    You don't need the asterix :) – A.B. Jul 30 '15 at 14:24
  • Adding the -l option means you'll just get the filename, without listing the file contents. – Arronical Jul 30 '15 at 14:25
1

Via find and grep

I don't use grep -r because in POSIX systems, you don't find -r parameter for grep.

find . -type f -print0 | xargs -0 grep 'your_email_address' {} \;

Or

find . -type f -exec grep -l -- 'your_email_address' +

There are many possibilities.

The command finds all files in the current folder and subfolders and passes the result to grep. grep finds the files with your_email_address.

  • 1
    Why not just grep -r 'your_email_address'? – saiarcot895 Jul 30 '15 at 14:19
  • Hmm, I'm a friend of find =) – A.B. Jul 30 '15 at 14:20
  • 2
    In its present state, this will not give the name of the file that contains the match. It will only give the match. – saiarcot895 Jul 30 '15 at 14:21
  • Sorry, corrected – A.B. Jul 30 '15 at 14:22
  • @saiarcot895 And in POSIX systems, you don't find -r parameter for grep. – A.B. Jul 30 '15 at 14:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.