我的硬盘里装满了文件,我需要在不知道文件名称的情况下找到某个特定文件。我只知道该文件包含一个电子邮件地址列表。有什么方法可以找到它吗?
答案1
您可以尝试使用grep -r
:
下面是一个示例,我在主目录的任何文件中查找文本“listen_address”:
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
通过find
和grep
我不使用,grep -r
因为在 POSIX 系统中,找不到 的-r
参数grep
。
find . -type f -print0 | xargs -0 grep 'your_email_address' {} \;
或者
find . -type f -exec grep -l -- 'your_email_address' +
有很多种可能性。
该命令查找当前文件夹和子文件夹中的所有文件,并将结果传递给grep
。grep
查找带有的文件your_email_address
。