问题描述
我在Linux和放大器的工作;庆典(或Cygwin的&安培; bash)的。
我有一个巨大的 - 的巨大的 - 目录结构,我必须找到在草堆几针
。具体来说,我正在寻找这些文件(20个左右):
foo.c的
bar.h
...
quux.txt
我知道,他们是在一个子目录下的某处。
。
我知道我能找到其中的任何一个找到。 -name -print的foo.c
。这个命令需要几分钟的时间来执行。
我怎样才能打印这些文件的名称及其完整的路径?我不想执行20个单独的找到
秒 - 。它会花很长时间。
我能给找到
从标准输入文件列表?从一个文件?是否有不同的命令,我想要做什么?
我必须先组装为使用循环或东西的命令行找到
与 -o
如果您的目录结构是巨大的,但不经常变化的,这是很好的运行。
CD /到/根/的/的/文件
找 。型的F&-print GT; ../LIST_OF_FILES.txt#,然后有时得心应手下一个太
找 。 ð型-print> ../LIST_OF_DIRS.txt
后,你可以非常快找到任何(使用grep,sed的,等..)和更新文件,只列出当树被改变。 (这是一个简单的更换,如果你没有定位
)
因此,
的grep'/foo.c$LIST_OF_FILES.txt #list所有的foo.c树..
当想要找到的文件列表,你可以尝试以下方法:
比fgrep -f wanted_file_list.txt< LIST_OF_FILES.txt
或者直接用find命令
找到。 F型-print |比fgrep -f wanted_file_list.txt
在 -f
为fgrep一样均值 - 从文件中读取模式,让您可以轻松grepping多模式输入...
I'm working in Linux & bash (or Cygwin & bash).
I have a huge--huge--directory structure, and I have to find a few needles in the haystack.
Specifically, I'm looking for these files (20 or so):
foo.c
bar.h
...
quux.txt
I know that they are in a subdirectory somewhere under .
.
I know I can find any one of them withfind . -name foo.c -print
. This command takes a few minutes to execute.
How can I print the names of these files with their full directory name? I don't want to execute 20 separate find
s--it will take too long.
Can I give find
the list of files from stdin? From a file? Is there a different command that does what I want?
Do I have to first assemble a command line for find
with -o
using a loop or something?
If your directory structure is huge but not changing frequently, it is good to run
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
after it you can really FAST find anything (with grep, sed, etc..) and update the file-lists only when the tree is changed. (it is a simplified replacement if you don't have locate
)
So,
grep '/foo.c$' LIST_OF_FILES.txt #list all foo.c in the tree..
When want find a list of files, you can try the following:
fgrep -f wanted_file_list.txt < LIST_OF_FILES.txt
or directly with the find command
find . type f -print | fgrep -f wanted_file_list.txt
the -f
for fgrep mean - read patterns from the file, so you can easily grepping input for multiple patterns...
这篇关于Unix的发现:从标准输入文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!