Unix find:来自stdin的文件列表

JXG*_*JXG 12 unix bash find

我在Linux&bash(或Cygwin&bash)工作.

我有一个庞大的 - 巨大的 - 目录结构,我必须在大海捞针中找到几根针.

具体来说,我正在寻找这些文件(20左右):

foo.c
bar.h
...
quux.txt
Run Code Online (Sandbox Code Playgroud)

我知道他们在某个子目录下..

我知道我可以找到他们中的任何一个 find . -name foo.c -print.此命令需要几分钟才能执行.

如何使用其完整目录名称打印这些文件的名称?我不想执行20个单独find的 - 它需要太长时间.

我可以find从stdin中提供文件列表吗?从文件?是否有一个不同的命令可以满足我的需求?

我必须先组装一个命令行对find-o使用循环或东西吗?

jm6*_*666 11

如果您的目录结构很大但不经常更改,那么最好运行

cd /to/root/of/the/files
find . -type f -print > ../LIST_OF_FILES.txt #and sometimes handy the next one too
find . -type d -print > ../LIST_OF_DIRS.txt
Run Code Online (Sandbox Code Playgroud)

在它之后你可以真正快速找到任何东西(使用grep,sed等...)并仅在更改树时更新文件列表.(如果你没有,它是一个简化的替代品locate)

所以,

grep '/foo.c$' LIST_OF_FILES.txt #list all foo.c in the tree..
Run Code Online (Sandbox Code Playgroud)

想要查找文件列表时,可以尝试以下操作:

fgrep -f wanted_file_list.txt < LIST_OF_FILES.txt
Run Code Online (Sandbox Code Playgroud)

或直接使用find命令

find . type f -print | fgrep -f wanted_file_list.txt
Run Code Online (Sandbox Code Playgroud)

-f对fgrep一样均值-从文件中读取模式,让您可以轻松快速的多模式输入grepping ...