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?
2 Answers
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
-
Adding the -l option means you'll just get the filename, without listing the file contents. Jul 30, 2015 at 14:25
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
-
-
2In its present state, this will not give the name of the file that contains the match. It will only give the match. Jul 30, 2015 at 14:21
-
-
@saiarcot895 And in POSIX systems, you don't find -r parameter for grep.– A.B.Jul 30, 2015 at 14:26