功能:

在指定目录下查找符合yyyy-MM-dd(-d)nnn模式的目录名,例如2020-03-22-b888

目标目录情况:

[root@localhost testfolder]# ll
total
drwxr-xr-x. root root Mar :
drwxr-xr-x. root root Mar : ---b001
drwxr-xr-x. root root Mar : ---b001
drwxr-xr-x. root root Mar : ---b001
drwxr-xr-x. root root Mar : ---b001
drwxr-xr-x. root root Mar : ---b001
drwxr-xr-x. root root Mar : -
drwxr-xr-x. root root Mar : archive
-rw-r--r--. root root Mar : a.txt
drwxr-xr-x. root root Mar : backup
-rw-r--r--. root root Mar : b.txt
[root@localhost testfolder]#

期待查找结果:

---b001  ---b001
---b001 ---b001 ---b001

代码:

#!/bin/bash

function findDirsUnder(){
folder=$ for dir in `find $folder -type d -regextype 'posix-egrep' -regex $folder+'/[0-9]{4}-[0-9]{2}-[0-9]{2}-b[0-9]{3}$'`;
do
echo $dir
done
} findDirsUnder "/root/testfolder"

执行结果:

[root@localhost bashs]# sh dir.sh
/root/testfolder/---b001
/root/testfolder/---b001
/root/testfolder/---b001
/root/testfolder/---b001
/root/testfolder/---b001
[root@localhost bashs]#

--2020年3月22日--

最新文章

  1. tp5 中 model 的查询方法
  2. Java中的virtual method
  3. loj 1108(spfa判负环)
  4. 安装Bind过程中提示丢失MSVCR110.dll的解决办法
  5. AngularJS+ckEditor管理ng-model
  6. 546A. Soldier and Bananas
  7. Asp.Net验证码2
  8. (转)CWnd与HWND的区别与转换
  9. HDU5812 Distance 构造,预处理
  10. Could not delete folder on Win7
  11. poj2594 (最小路径覆盖 + floyd)
  12. BestCoder Round #75 King's Cake 模拟&&优化 || gcd
  13. 记一次 SSM 分页
  14. How to hosts
  15. bs4
  16. 关于react的一些东西
  17. python3 字典的常用方法
  18. c++ 替换修改一个文件夹下的所有文件的文件名
  19. APP的上线和推广——线上推广渠道
  20. jmeter 计数器 (可自动生成新数字、注册专用)

热门文章

  1. 2020-07-04:tcp三次握手干了啥?time_wait什么时候出现?
  2. JS实例-DOM查询
  3. 【ASP.NET Core学习】使用JWT认证授权
  4. go语言gRPC系列(二) - 为gRPC添加证书
  5. 【算法•日更•第三十九期】迭代加深搜索:洛谷SP7579 YOKOF - Power Calculus 题解
  6. LinkedBlockingQueue 和 ConcurrentLinkedQueue的区别
  7. Jmeter 常用函数(4)- 详解 __setProperty
  8. JavaScript学习系列博客_31_JavaScript Math 工具类
  9. springboot + mybatisPlus 入门实例 入门demo
  10. springboot 新建的时候 pom 第一行出现红叉,项目可以正常运行