我需要一个查找命令来输出某个目录中包含“e”的所有文件名,但“e”不能位于文件名的开头/结尾。
$ ls .
emil eva extreme let yes
我正在寻找的 find 命令应该只输出 let
和 yes
,而不是其他名称。
到目前为止我尝试过的事情:
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/