./color_a.txt
./color_b.txt
./color_c.txt
./color/color_d.txt
./color/blue.txt
./color/red.txt
./color/yellow.txt
find ./*color* -type f
./color_a.txt
./color_b.txt
./color_c.txt
./color/color_d.txt
./color/blue.txt
./color/red.txt
./color/yellow.txt
./color_a.txt
./color_b.txt
./color_c.txt
./color/color_d.txt
结果还包括匹配的父目录下的所有不匹配的文件名。 我怎样才能获得名称与 color 模式直接匹配的文件?
非常感谢!
答案 0 :(得分:1)
您可能想要的文件名过滤是一个简单的 paper
wood
plastic
fire
water
house
测试:
-name <glob-pattern>
来自find -name '*color*' -type f
:
man find
正如旁注,当你写道:
-name pattern
Base of file name (the path with the leading directories removed) matches shell
pattern pattern. Because the leading directories are removed, the file names
considered for a match with -name will never include a slash, so `-name a/b' will
never match anything (you probably need to use -path instead).
shell扩展了(未引用的)glob模式find ./*color* -type f
,真正执行的内容(./*color*
看到的内容)是这样的:
find
因此在所有这些位置产生一个文件列表。
答案 1 :(得分:0)
您可以使用正则表达式选项
find -regex ".*color_.*" -type f