find 用正则表达式查找符合yyyy-mm-dd-bddd模式的目录

yyyy-dd-mm-bddd模式解释:

yyyy:年份,如2020

mm:月份,如03

dd:日期,如22

-b:意为备份,-b为固定字符串

ddd:三位序列号,从001~999

符合此格式的目录名如2020-03-22-b888,2019-09-31-b001等.

现当前目录中有一些这样的目录,需要把他们找出该怎么做?请看命令:

find . -type d -regextype 'posix-egrep' -regex '\./[0-9]{4}-[0-9]{2}-[0-9]{2}-b[0-9]{3}$'

命令解释:

find . -type d -regexttype
'posix-egrep'
-regex
'\./[0-9]{4}-[0-9]{2}-[0-9]{2}-b[0-9]{3}$'
Linux下查找命令 查找路径为当前路径 查找类型 目录 使用正则表达式型号 扩展正则表达式 使用正则表达式  

当前目录中文件:

[root@localhost testfolder]# ls
2020             2020-02-20-b001  2020-03-21-b001  2020-20  a.txt   b.txt
2020-01-10-b001  2020-03-20-b001  2020-03-22-b001  archive  backup

执行结果:

[root@localhost testfolder]# find . -type d -regextype 'posix-egrep' -regex '\./[0-9]{4}-[0-9]{2}-[0-9]{2}-b[0-9]{3}$'
./2020-03-21-b001
./2020-03-22-b001
./2020-03-20-b001
./2020-02-20-b001
./2020-01-10-b001

--2020年3月22日--

参考资料:https://blog.csdn.net/bodybo/article/details/84981109

posted @ 2020-03-22 14:58  逆火狂飙  阅读(504)  评论(0编辑  收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东