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
相关推荐
DTS小夏18 分钟前
Linux 系统 + IDEA+Scala 插件:新手进阶开发指南
linux·scala·intellij-idea
老黄编程27 分钟前
--gpu-architecture <arch> (-arch)
linux·人工智能·机器学习
肖爱Kun29 分钟前
LINUX中USB驱动架构—URB请求块
linux·驱动
wanhengidc44 分钟前
云手机在办公领域中自动化的应用
运维·智能手机·自动化
知星小度S3 小时前
系统核心解析:深入操作系统内部机制——进程管理与控制指南(一)【进程/PCB】
linux·运维·服务器·进程
编码浪子6 小时前
趣味学RUST基础篇(异步)
服务器·rust·负载均衡
码农101号7 小时前
运维安全05 - iptables规则保存与恢复
运维·网络·安全
Empty_7777 小时前
SELinux安全上下文
linux·服务器·安全
bug攻城狮8 小时前
解决Ubuntu中apt-get -y安装时弹出交互提示的问题
linux·运维·ubuntu
xiachong278 小时前
ubuntu18.04安装PCL1.14
linux·ubuntu