使用 -regex 和 -exec 查找命令,需要正则表达式帮助
我有一个目录,里面有一堆人物图像。不幸的是,图像所来自的系统对于一堆人物图像有其自己的唯一ID,这些图像未在企业的任何其他系统中使用(即客人有一张照片,但实际上并不在员工/客户数据库中...... .就在图片服务器的存储中)。幸运的是,8 个或更多整数后跟扩展名的图片是不需要的(我见过 .bmp 和 .jpg...但可能还有其他)。在将 ls -lh 替换为 rm -f 并编写删除其他系统照片的脚本之前,我已尝试使用以下 find 命令作为测试。我猜我误解了正则表达式,因为通常都是这种情况,但在我看来,以下内容似乎适合我正在寻找的内容。 \d{8,} 似乎不起作用,因为删除它会发现一切都很好,但我不想要一切......只是那些带有 8 个或更多整数的整数,后跟任何内容。我在这里忽略了什么?
find /path/to/dir -regex '\/path\/to\/dir\/\d{8,}.*' -exec ls -lh {} \;
谢谢。
I have a directory with a bunch of person images in it. Unfortunately the system the images are coming from has its own unique IDs for a bunch of person images that are not used in any other systems at the business (ie guests have a picture but aren't actually in the employee/customer db....just in the picture server's storage). Fortunately pictures of 8 or more integers followed by an extension are unwanted (I've seen .bmp and .jpg...but there could be others). I've attempted the following find command as a test before I swap the ls -lh with an rm -f and script the removal of the photos for other systems. I am guessing I am misunderstanding regular expressions, as that is usually the case, but everywhere I look sure seems like the following should work for what I am looking for. The \d{8,} does not appear to be working as removing it finds everything just fine, but I don't want everything....just those with 8 or more integers followed by whatever. What am I overlooking here?
find /path/to/dir -regex '\/path\/to\/dir\/\d{8,}.*' -exec ls -lh {} \;
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道
find
正则表达式类型是否特定于系统。我在 Linux 中看到它有几种类型的正则表达式(POSIX 与 Emacs 不同)。 find 中的默认正则表达式似乎与 emacs 类似。我发现find
也有一个-regextype
选项,因此,使用posix-extend
你可以获得与你想要的类似的东西:但是这些类型的正则表达式上没有
\d
(我认为它们仅来自 Perl 类型的正则表达式),并且不需要/
的反斜杠。无论如何,这些作品。I don't know if
find
regex types are system-specific. I've seen in the Linux one that it has several types of regular expressions (POSIX are different from Emacs). It seems that the default regex in find are emacs-like. I've seen thatfind
also has a-regextype
option, so, using theposix-extended
you can get something similar to what you want:but you don't have
\d
on those type of regexes (I think they come from Perl-type regex only), and don't need backslashes for/
. Anyway, these works.