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 小时前
五分钟就能搭好的socks5为啥我装了一个小时😭 进来看小丑
linux·后端
qq_364371721 小时前
Docker 常见命令
运维·docker·容器
Insist7532 小时前
K8s--调度管理:node节点、Pod亲和性、污点与容忍
linux·容器·kubernetes
VVVVWeiYee4 小时前
TCP/UDP详解(一)
运维·网络·tcp/ip·udp·信息与通信
Xの哲學4 小时前
Linux PCI 子系统:工作原理与实现机制深度分析
linux·网络·算法·架构·边缘计算
谢尔登4 小时前
【计算机网络】 IPV4和IPV6区别
运维·服务器·计算机网络
@Demi4 小时前
vsCode或Cursor 使用remote-ssh插件链接远程终端
服务器·ide·vscode·ssh
he_xiao1235 小时前
centos配置ip地址不生效
linux
努力努力再努力wz5 小时前
【c++进阶系列】:万字详解多态
java·linux·运维·开发语言·c++
杭州泽沃电子科技有限公司5 小时前
工业环境电缆火灾预防的分布式光纤在线监测
运维·人工智能·科技·安全