使用 find 基于 md5 匹配文件

使用 find 基于 md5 匹配文件

我的目录中有一堆 js 和 css 文件。其中一些已根据其内容的 md5() 命名(看起来像f10521a21bb013cb81e0909809818ad6.js)。我想使用 find 来匹配这些文件。为什么返回 0 结果?

find -regex "^[A-f0-9]{32}\.(?:js|css)$"

答案1

  • 正则表达式与路径匹配,而不仅仅是文件名,因此不要将其锚定到字符串的开头。
  • 默认的 emacs 类型正则表达式似乎不喜欢间隔。选择另一个。
  • 其他正则表达式类型似乎都不喜欢非捕获组。

假设您使用的是 GNU ,这些工作有效find

find . -regextype posix-awk -regex ".*/[a-f0-9]{32}\.(js|css)$"

find . -regextype posix-basic -regex ".*/[a-f0-9]\{32\}\.\(js\|css\)$"

find . -regextype posix-egrep -regex ".*/[a-f0-9]{32}\.(js|css)$"

find . -regextype posix-extended -regex "/[a-f0-9]{32}\.(js|css)$"

相关内容