使用带有确切位数的正则表达式查找文件(find files using regex with exact digits number)

编程入门 行业动态 更新时间:2024-10-24 00:21:18
使用带有确切位数的正则表达式查找文件(find files using regex with exact digits number)

我正在尝试在linux上找到与这些文件匹配的所有文件:

frontend_prod_20100112.log frontend_prod_20110101.log frontend_prod_20120101.log frontend_prod_20121231.log

这里唯一的变量是8位数(正好是8位)。 我正在尝试运行:

find . -regex ".*frontend_prod_[0-9]{8}\.log"

要么

find . -regex ".*frontend_prod_(\d){8}\.log"

但它不起作用。

谢谢你的帮助。

I'm trying to find all files on linux that would match files like these:

frontend_prod_20100112.log frontend_prod_20110101.log frontend_prod_20120101.log frontend_prod_20121231.log

the only variable here is 8 digits inside (exactly 8). I'm trying to run:

find . -regex ".*frontend_prod_[0-9]{8}\.log"

or

find . -regex ".*frontend_prod_(\d){8}\.log"

but it doesn't work.

Thanks for any help.

最满意答案

由于这是POSIX,因此您需要稍微不同的语法:

find . -regex ".*frontend_prod_[0-9]\{8\}\.log"

Since this is POSIX, you need a slightly different syntax:

find . -regex ".*frontend_prod_[0-9]\{8\}\.log"

更多推荐

本文发布于:2023-08-03 13:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1389345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位数   确切   文件   正则表达式   find

发布评论

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

>www.elefans.com

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