linux - find cmd 的正则表达式输出其中包含 'e' 但不在名称开头/结尾的所有文件

标签 linux bash expression

我需要一个查找命令来输出某个目录中包含“e”的所有文件名,但“e”不能位于文件名的开头/结尾。

$ ls .
emil eva extreme let yes

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

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

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

我想不通的类似问题:

列出所有文件:

  • 以 a、z 或 y 开头

  • 不要以 x、z 或 y 开头

  • 只包含一个字符

  • 只包含两个字符

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

提前致谢:)

最佳答案

想明白就输入命令

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

关于linux - find cmd 的正则表达式输出其中包含 'e' 但不在名称开头/结尾的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56817812/

相关文章:

linux - 如何将子命令传回 bash 完成?

c# - 在 C# 中使用正则表达式(正则表达式)从字符串中获取值

linux - 如何在一行命令中将密码应用于 sudo 并执行 su root?

python - 无法从 python 3.5.2 升级到 3.6

linux - 使用 rsync 进行增量备份的脚本

linux - 在 bash 中转换日期格式

linux - 如何在 Linux 中创建一个静态链接位置独立的可执行 ELF?

linux - ELF 中 set-uid 和 INTERP(动态链接器)的相对路径的安全问题

css - 使用类似 “input[class~=”的有效“&& type =“checkbox”]?

javascript - Mozilla 雷鸟 "FiltaQuilla"; JavaScript 和正则表达式