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
相关推荐
猫头虎1 分钟前
OpenClaw开源汉化发行版:介绍、下载、安装、配置教程
运维·windows·开源·aigc·ai编程·agi·csdn
强风7943 分钟前
Linux-传输层协议TCP
linux·网络·tcp/ip
那我掉的头发算什么9 分钟前
【Mybatis】Mybatis-plus使用介绍
服务器·数据库·后端·spring·mybatis
wazmlp0018873699 分钟前
第五次python作业
服务器·开发语言·python
looking_for__24 分钟前
【Linux】应用层自定义协议与序列化
linux·服务器·网络
云中飞鸿24 分钟前
VS编写QT程序,如何向linux中移植?
linux·开发语言·qt
唐梓航-求职中24 分钟前
技术-算法-leetcode-1606. 找到处理最多请求的服务器(易懂版)
服务器·算法·leetcode
晚风_END29 分钟前
Linux|操作系统|elasticdump的二进制方式部署
运维·服务器·开发语言·数据库·jenkins·数据库开发·数据库架构
嵌入小生00730 分钟前
Standard IO -- Continuation of Core Function Interfaces (Embedded Linux)
linux·vim·嵌入式·标准io·vscode
Zach_yuan31 分钟前
传输层之TCP/UDP 核心原理全解析:从协议基础到实战机制
linux·网络协议·tcp/ip·udp