简体   繁体   English

Ubuntu 13.04:查找以。结尾的文件

[英]Ubuntu 13.04: Find files ending in

Can someone please tell me how I'm misusing find? 有人可以告诉我我是如何滥用发现的吗?

I want to find all files in a directory that end in .config. 我想找到以.config结尾的目录中的所有文件。

$:~/esrc$ find . -type f
./t.config
./util/ebin/config.beam
./util/ebin/gen_spec.beam
./util/etc/util.config
./util/etc/v.config
./util/src/config.erl
./util/src/gen_spec.erl
./util/src/v.config
./util/u.config

My first thought was to use find . 我的第一个想法是使用find。 -type f -name *.config -type f -name * .config

Unfortunately that's only finding a file in the root directory. 不幸的是,这只是在根目录中找到一个文件。

$:~/esrc$ find . -type f -name *.config
./t.config

The same command does work to find all *.erl files though... 虽然相同的命令可以找到所有* .erl文件...

$:~/esrc$ find . -type f -name *.erl
./util/src/config.erl
./util/src/gen_spec.erl

Any clue why this works for *.erl but not *.config? 任何线索为什么这适用于* .erl而不是* .config?

Thanks. 谢谢。

引用外卡,即

find . -type f -name '*.config'

The confusion here is that the wildcard (the * character) is interpreted by the shell before it makes it to the find command. 这里的混淆是外壳 (*字符) 进入find命令之前shell解释。 To get around that issue you need to escape it: 要解决该问题,您需要逃避它:

find . -type f -name \*.config

By escaping the * with the \\ the shell will pass the * through to the find command. 通过使用\\转义*,shell将把*传递给find命令。

An example would be if you had a file named foo.config in the current directory, the shell would expand the wildcard to foo.config and pass that to find, so the resulting command from the find command's perspective would be: 例如,如果当前目录中有一个名为foo.config的文件,shell会将通配符扩展为foo.config并将其传递给find,因此查找命令的透视图中的结果命令为:

find . -type f -name foo.config

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM