java 正则表达式find_如何使用正则表达式与find命令?

这篇博客介绍了如何使用`find`命令结合`-regextype`选项和正则表达式来精确匹配文件名。示例中展示了查找以特定36位十六进制数字和短划线组合结尾的.jpg文件的方法,并提示了正确指定路径的必要性。内容还包含了find命令的版本信息和可用的正则表达式类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

find . -regextype sed -regex ".*/[a-f0-9\-]\{36\}\.jpg"

请注意,您需要在开头指定 .*/ ,因为 find 与整个路径匹配 .

例:

susam@nifty:~/so$ find . -name "*.jpg"

./foo-111.jpg

./test/81397018-b84a-11e0-9d2a-001b77dc0bed.jpg

./81397018-b84a-11e0-9d2a-001b77dc0bed.jpg

susam@nifty:~/so$

susam@nifty:~/so$ find . -regextype sed -regex ".*/[a-f0-9\-]\{36\}\.jpg"

./test/81397018-b84a-11e0-9d2a-001b77dc0bed.jpg

./81397018-b84a-11e0-9d2a-001b77dc0bed.jpg

我的发现版本:

$ find --version

find (GNU findutils) 4.4.2

Copyright (C) 2007 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.

Built using GNU gnulib version e5573b1bad88bfabcda181b9e0125fb0c52b7d3b

Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS() CBO(level=0)

susam@nifty:~/so$

susam@nifty:~/so$ find . -regextype foo -regex ".*/[a-f0-9\-]\{36\}\.jpg"

find: Unknown regular expression type `foo'; valid types are `findutils-default', `awk', `egrep', `ed', `emacs', `gnu-awk', `grep', `posix-awk', `posix-basic', `posix-egrep', `posix-extended', `posix-minimal-basic', `sed'.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值