find指令中使用正则表达式

linux查找命令能结合正则表达式吗

find命令要使用正则表达式需要结合-regex参数

另,-type参数可以指定查找类型(f为文件,d为文件夹)

bash 复制代码
root@localhost:~/regular_expression# ls -alh
总计 8.0K
drwxr-xr-x.  5 root root   66  4月 8日 16:26  .
dr-xr-x---. 19 root root 4.0K  4月 8日 16:25  ..
drwxr-xr-x.  2 root root    6  4月 7日 09:55  1213
drwxr-xr-x.  2 root root    6  4月 8日 16:26  cc
-rw-r--r--.  1 root root  660  4月 7日 15:04  regular_express.txt
drwxr-xr-x.  2 root root    6  4月 7日 09:54 't a'
bash 复制代码
# .* -->代表零个或多个任意字符的意思
#因为 . 与 * 两者是 "相乘" 的关系,等于 . 所代表的 一个任意字符 乘以 * 所代表的零个到无穷多个字符。所以,包含从零个开始到任意多个字符。
#查找以 .txt结尾的文件
root@localhost:~/regular_expression# find . -type f -regex ".*\.txt"
./regular_express.txt
root@localhost:~/regular_expression# find . -type f -regex ".*c"

#查找包含任意字符的文件
root@localhost:~/regular_expression# find . -type f -regex ".*"
./regular_express.txt

 
root@localhost:~/regular_expression# find . -regex ".*"
.
./t a
./1213
./regular_express.txt
./cc

root@localhost:~/regular_expression# find . -regex ".*c"
./cc

root@localhost:~/regular_expression# find . -regex ".*c$"
./cc

root@localhost:~/regular_expression# find . -regex "^.*c$"
./cc

#指定查找类型为文件夹类型
root@localhost:~/regular_expression# find . -type d -regex "^.*c$"
./cc
相关推荐
阿巴阿巴boer9 分钟前
用wsl搭建远程linux服务器
linux·运维·服务器·ssh
starvapour43 分钟前
Ubuntu硬盘的创建分区、格式化与挂载
linux·ubuntu
lisanmengmeng1 小时前
docker 方式安装部署禅道zentao(五)
运维·docker·容器
小立爱学习1 小时前
ARM64 指令 --- CASP / CASPA / CASPL / CASPAL
linux·c语言
乘风!1 小时前
NSSM启动tomcat部署Java程序
java·服务器·后端·tomcat
知识分享小能手1 小时前
CentOS Stream 9入门学习教程,从入门到精通,CentOS Stream 9 中 Linux C 编程 —语法详解与实战案例(13)
linux·学习·centos
wanhengidc2 小时前
云手机的硬件依赖性如何?
运维·服务器·智能手机·云计算
piaoroumi2 小时前
UVC调试
linux·运维·前端
VekiSon2 小时前
Linux系统编程——标准IO
linux·运维·服务器
Evan芙2 小时前
DNS服务器类型,解析答案,正反解析域,资源记录定义总结
运维·服务器