在 /usr/include 中找到所有以元音开头的头文件

xyz*_*xyz -5 command-line regex find

我需要找到所有/usr/include以元音开头的标题(a,e,i,o,u)

例子:

acpi.h 
aclinux.h
ah.h 
...
Run Code Online (Sandbox Code Playgroud)

我不知道该怎么做,我用 grep 尝试了一些东西,但我没有弥补。

αғs*_*нιη 9

有一种使用ls命令的简单方法:

ls /usr/include/[aeiou]*.h
Run Code Online (Sandbox Code Playgroud)

您也可以使用find带有-regex选项的命令,如下所示:

ls /usr/include/[aeiou]*.h
Run Code Online (Sandbox Code Playgroud)
find /usr/include -type f -regextype "posix-extended" -iregex '^\.\/(a|e|i|o|u).*\.h$'
Run Code Online (Sandbox Code Playgroud)
^\.\/[aeiou].*\.h$ 
Run Code Online (Sandbox Code Playgroud)

^./[aeiou].*.h$

解释:

  • ^ 是文件名开头的锚点(或更好地开始文件路径)
  • \.\/仅匹配./(单点后跟斜线)
  • (a|e|i|o|u)是一组比赛。将匹配aor( |) e, i,ou从文件名开头的 first 之后./;或者你可以只使用 character-class [aeiou]
  • .* 匹配元音单词后的任何字符
  • \. 匹配单点字符,和
  • h$匹配h文件名末尾的字符($文件名末尾的锚点)

  • @don.joey 看看这里 http://www.regexper.com/ (2认同)