[bash]用于查找指定格式目录的程序
2024-08-23 14:41:59
功能:
在指定目录下查找符合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日--
最新文章
- tp5 中 model 的查询方法
- Java中的virtual method
- loj 1108(spfa判负环)
- 安装Bind过程中提示丢失MSVCR110.dll的解决办法
- AngularJS+ckEditor管理ng-model
- 546A. Soldier and Bananas
- Asp.Net验证码2
- (转)CWnd与HWND的区别与转换
- HDU5812 Distance 构造,预处理
- Could not delete folder on Win7
- poj2594 (最小路径覆盖 + floyd)
- BestCoder Round #75 King&;#39;s Cake 模拟&;amp;&;amp;优化 || gcd
- 记一次 SSM 分页
- How to hosts
- bs4
- 关于react的一些东西
- python3 字典的常用方法
- c++ 替换修改一个文件夹下的所有文件的文件名
- APP的上线和推广——线上推广渠道
- jmeter 计数器 (可自动生成新数字、注册专用)
热门文章
- 2020-07-04:tcp三次握手干了啥?time_wait什么时候出现?
- JS实例-DOM查询
- 【ASP.NET Core学习】使用JWT认证授权
- go语言gRPC系列(二) - 为gRPC添加证书
- 【算法•日更•第三十九期】迭代加深搜索:洛谷SP7579 YOKOF - Power Calculus 题解
- LinkedBlockingQueue 和 ConcurrentLinkedQueue的区别
- Jmeter 常用函数(4)- 详解 __setProperty
- JavaScript学习系列博客_31_JavaScript Math 工具类
- springboot + mybatisPlus 入门实例 入门demo
- springboot 新建的时候 pom 第一行出现红叉,项目可以正常运行