在 Linux 中,可通过 find
命令的 -regex
参数结合正则表达式进行文件匹配。需注意以下要点:
-regex
默认匹配完整路径,正则语法需符合find
的规范(如使用.*
代替*
);- 添加
-regextype
指定正则类型(如posix-extended
); - 使用
-iregex
忽略大小写; - 示例:
find /path -regextype posix-extended -regex ".*\\.(txt|log)$"
匹配后缀为 txt 或 log 的文件。