用于查找cmd的正则表达式以输出所有带有'e'但不在名称开头/结尾的文件



我需要一个find命令来输出包含'e'的特定目录中的所有文件名,但是'e'不得在文件名的开始/结尾处。

$ ls .
emil eva extreme let yes

我正在寻找的查找命令只能输出letyes,而不是其他名称。

我到目前为止尝试过的事情:

find dir -name "*e*
find dir -name "^e$"
find dir -name "[a-z]e[a-z]"

我无法弄清楚的类似问题:

列出所有文件:

  • 以a,z或y

  • 开头
  • 不要以x,z或y

  • 开始
  • 仅由一个char组成

  • 仅由两个字符组成

  • 仅由两个或三个字符组成

预先感谢:(

如果您想了解,请输入命令

man find

我认为您可以轻松解决其他问题,如果没有,请在另一个问题中询问他们。用字母" e"的案例解决方案:

find .  -maxdepth 1 -type f -regextype sed -regex  '^./[^e].*e.*[^e]$'

说明:

find. looks in the current directory
-maxdepth 1 does not go into subdirectories
-type f only displays files
-regextype sed sets the type of regular expressions to those for sed
-regex '^./[^e].*e.*[^e]$'   the regular expression
^ the beginning of the sequence
. literal dot
/ literal '/'
[^e] character not being the letter e
.* any number of any characters
e literal sign e
$ end of the sequence

最新更新