使用带有确切位数的正则表达式查找文件(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.logthe 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"更多推荐
发布评论