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
相关推荐
寒水馨6 分钟前
Linux下载、安装 Codex CLI(附安装包codex-x86_64-unknown-linux-musl.tar.gz)
linux·openai·终端·ai编程·codex·智能体·codex cli
其实防守也摸鱼26 分钟前
KMP全栈开发:从Android到AI Agent的技术演进与实践
android·运维·网络·人工智能·学习·安全·macos
冰封之寂9 小时前
Docker 资源管理终极指南:CPU、内存与 IO 的精细化控制
linux·运维·服务器·docker·云计算
xiaoye-duck9 小时前
《Linux系统编程》Linux 系统多线程(五):<线程同步与互斥>线程互斥(上):从条件变量到生产者消费者模型详解
linux·线程
小柯南敲键盘10 小时前
图片翻译API接入与自动化实现指南
运维·python·自动化
云计算磊哥@10 小时前
运维开发宝典058-大型网站nginx服务器管理全集4
服务器·nginx·运维开发
9523611 小时前
Docker - 基础
运维·后端·docker·容器
Promise微笑11 小时前
智能激光清障仪选型指南:高效运维与安全保障的关键考量
运维·安全
Code_Ignis11 小时前
docker国内可用源(持续维护)
运维·docker·容器
一叶龙洲11 小时前
向日葵远程Ubuntu,支持隐私屏
linux·运维·ubuntu