庆典:递归查找匹配某种样式的所有文件 [英] bash: recursively find all files that match a certain pattern

查看:114
本文介绍了庆典:递归查找匹配某种样式的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到(或更具体地说,计数)与此模式匹配的所有文件:

I need to find (or more specifically, count) all files that match this pattern:

* /富/ *。doc的

*/foo/*.doc

当第一个通配符星号包括可变数量的子目录。

Where the first wildcard asterisk includes a variable number of subdirectories.

推荐答案

通过GNU发现你可以使用正则表达式,它(不像 -name )匹配整个路径:

With gnu find you can use regex, which (unlike -name) match the entire path:

find . -regex '.*/foo/[^/]*.doc'

要仅计算文件的数量:

find . -regex '.*/foo/[^/]*.doc' -printf '%i\n' | wc -l

(即%I 格式code使找到打印索引节点号而不是文件名;不同的文件名,inode编号是保证没有像换行字符,所以计算更加可靠。感谢@tripleee的建议。)

(The %i format code causes find to print the inode number instead of the filename; unlike the filename, the inode number is guaranteed to not have characters like a newline, so counting is more reliable. Thanks to @tripleee for the suggestion.)

我不知道这是否会在OSX工作,虽然。

I don't know if that will work on OSX, though.

这篇关于庆典:递归查找匹配某种样式的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆