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?
Asked
Active
Viewed 1,432 times
2
-
GUI or cli? both are in the dupes above :) – Jacob Vlijm Jul 30 '15 at 14:26
2 Answers
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
.

A.B.
- 90,397
-
1
-
-
2In 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
-
-
-
@A.B. if you like
find
, why not just usegrep -l
with it? e.g.find . -type f -exec grep -l -- 'email_address' {} +
– steeldriver Jul 30 '15 at 14:29 -
@A.B. since grep can take multiple files on the command line,
{} +
should be more efficient than{} \;
in the second command. In your first command,\;
seems superfluous since{}
is an argument toxargs
, notfind -exec
. – steeldriver Jul 30 '15 at 15:35 -
@steeldriverb thank you again, in on mobile and in a train it's hard to change answers. :) I was always in the
xargs
mode. – A.B. Jul 30 '15 at 15:39
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

Aaron
- 6,714
-
2
-
Adding the -l option means you'll just get the filename, without listing the file contents. – Arronical Jul 30 '15 at 14:25