简体   繁体   English

为什么这个正则表达式不能在 linux 上使用 find 命令

[英]why this regex is not working with find command on linux

I am trying to execute this command我正在尝试执行此命令

find /home/scratch/test_cases/deleted/2nmW1wDfb5/ -iregex '.*/moodys_munis_full_refresh_flat_file_\d+.zip' -type f

It cannot find any file but the file is there when I do ls它找不到任何文件,但是当我执行 ls 时文件在那里

ls /home/scratch/test_cases/deleted/2nmW1wDfb5/moodys_munis_full_refresh_flat_file_2.zip

Result is结果是

/home/scratch/test_cases/deleted/2nmW1wDfb5/moodys_munis_full_refresh_flat_file_2.zip

Try:尝试:

find ... -iregex '.*[0-9]+.zip' -type f

instead.反而。 Or run或者运行

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

to get a list of known -regextypes on your system, and try获取系统上已知的 -regextypes 列表,然后尝试

find ... -regextype sed -iregex '.*[0-9]+.zip' -type f

and the other options, if you don't know, what which style stands for.以及其他选项,如果您不知道哪种风格代表什么。

On my system, \\d doesn't work with any of the options:在我的系统上, \\d 不适用于任何选项:

for rt in "findutils-default" "awk" "egrep" "ed" "emacs" "gnu-awk" "grep" "posix-awk" "posix-basic" "posix-egrep" "posix-extended" "posix-minimal-basic" "sed"
do 
   echo -n $rt" "
   find . -type f -regextype $rt -iregex '.*ro.*2\d+.scala'
   echo
done

findutils-default 
awk 
egrep 
ed 
emacs 
gnu-awk 
grep 
posix-awk 
posix-basic 
posix-egrep 
posix-extended 
posix-minimal-basic 
sed 

while rectangle braces are understood by about 50% of them:大约 50% 的人理解矩形大括号:

for rt in "findutils-default" "awk" "egrep" "ed" "emacs" "gnu-awk" "grep" "posix-awk" "posix-basic" "posix-egrep" "posix-extended" "posix-minimal-basic" "sed"
do 
   echo -n $rt" "
   find . -type f -regextype $rt -iregex '.*ro.*2[0-9]+.scala'
   echo
done

findutils-default ./rot1-25.scala

awk ./rot1-25.scala

egrep ./rot1-25.scala

ed 
emacs ./rot1-25.scala

gnu-awk ./rot1-25.scala

grep 
posix-awk ./rot1-25.scala

posix-basic 
posix-egrep ./rot1-25.scala

posix-extended ./rot1-25.scala

posix-minimal-basic 
sed 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM