开发者

find command with -regex and -exec, regex help needed

I have a directory with a bunch of person images in it. Unfortunately the system the images are开发者_C百科 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.


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 that find also has a -regextype option, so, using the posix-extended you can get something similar to what you want:

find /path/to/dir -regextype posix-extended -regex '/path/to/dir/[0-9]{8,}.*' -exec ls -lh {} \;

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜