Dij*_*tra 70 regex unix linux bash find
我在使用find
命令的正则表达式时遇到了麻烦.可能是我不明白在命令行上逃避的事情.
为什么这些不一样?
find -regex '.*[1234567890]'
find -regex '.*[[:digit:]]'
Run Code Online (Sandbox Code Playgroud)
Bash,Ubuntu
bmk*_*bmk 69
你应该看一下-regextype
参数find
,参见manpage:
-regextype type
Changes the regular expression syntax understood by -regex and -iregex
tests which occur later on the command line. Currently-implemented
types are emacs (this is the default), posix-awk, posix-basic,
posix-egrep and posix-extended.
Run Code Online (Sandbox Code Playgroud)
我猜这种emacs
类型不支持该[[:digit:]]
构造.我尝试了它,posix-extended
它按预期工作:
find -regextype posix-extended -regex '.*[1234567890]'
find -regextype posix-extended -regex '.*[[:digit:]]'
Run Code Online (Sandbox Code Playgroud)
kur*_*umi 27
请注意,这-regex
取决于整个路径.
-regex pattern
File name matches regular expression pattern.
This is a match on the whole path, not a search.
Run Code Online (Sandbox Code Playgroud)
你实际上不必使用-regex
你正在做的事情.
find . -iname "*[0-9]"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
111957 次 |
最近记录: |