庆典:递归查找匹配某种样式的所有文件

编程入门 行业动态 更新时间:2024-10-28 02:21:57
本文介绍了庆典:递归查找匹配某种样式的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

庆典:递归查找匹配某种样式的所有文件

本文发布于:2023-08-04 06:49:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1294009.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   庆典   样式   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!