仅使用 find 搜索 32 个字符长的目录

问题描述 投票:0回答:1

假设我有一个包含很多子目录的目录:

04762b39018e3cf4b1a2c6a304919b75
06e0caf156de30dd962cf6b9300aba66
1f1d0cb1b810336299cda5426d0f12f5
2fe7a428eb303da6846800fa20ab7ed4
41e0136413703b0685d6799f8a22a8e6
asdf
1234
Databases

其中一些目录的长度正好是 32 个字符(实际上是 md5hash),我想找到它们。在这种情况下不需要递归搜索。我尝试使用这个命令:

find /root/my/subdir -maxdepth 1 -type d -regex '^.*[a-fA-F0-9]{32}$'

我会得到结果:

04762b39018e3cf4b1a2c6a304919b75
06e0caf156de30dd962cf6b9300aba66
1f1d0cb1b810336299cda5426d0f12f5
2fe7a428eb303da6846800fa20ab7ed4
41e0136413703b0685d6799f8a22a8e6

但我什么也没得到。就我而言,我更喜欢

find
,因为这样以后就可以很容易地传递 bash 命令,但任何 bash 兼容的单行代码都会很好。

linux bash shell find
1个回答
0
投票

根据您的

find
版本,您可能只需要打开
egrep
:

$ find /root/my/subdir -maxdepth 1 -type d -regextype egrep -regex '^.*[a-fA-F0-9]{32}$'
© www.soinside.com 2019 - 2024. All rights reserved.