正则表达式匹配源码包版本号

ls | grep -E  "apache-tomcat-([0-9]).([0-9])+.([0-9])+.tar.gz"

ls | grep -E  "jdk-([0-9])([a-z])([0-9]{2})-linux-x64.rpm"

find / -regextype "posix-egrep" -regex .*"apache-tomcat-([0-9]).([0-9])+.([0-9])+.tar.gz"

find path -regex "xxx"
find path -iregex "xxx"
这两条命令都是运用base-regexp对文件路径进行匹配,iregex忽略大小写。
但是给出的正则表达式必须要匹配完整的文件路径
比如:find / -regex "find" 这样子是找不到/usr/bin/find的,要像这样find / -regex ".*find"或者更精确一点find / -regex ".*/find"
如果要使用扩展的正则表达式,对于BSD系的find可以在路径名前加一个"-E"选项
GNU的find支持多种风格的正则表达式,用-regextype 指定所使用的正则表达式类型,可选的有emacs(默认),posix-awk,posix-basic,posix-egrep,posix-extended,喜欢了grep -E,所以我就用posix-egrep了

find / -regextype "posix-egrep" -regex ".*/find"

原文地址:https://www.cnblogs.com/sqbk/p/5809688.html