3

我试过了'find -name .html$''find -name .html\>'
没有工作。

我想知道为什么这两个是错误的,什么是没有通配符的正确使用?

4

4 回答 4

5

你需要的是

find -name '*.html'

或者对于正则表达式:

find -regex '.*/.*\.html'

要忽略大小写,请使用 -iname 或 -iregex:

find -iname '*.html'
find -iregex '.*/.*\.html'

手册-name

   -name pattern
          Base of file name (the path with the leading directories
          removed) matches shell pattern pattern.  The metacharacters
          (`*', `?', and `[]') match a `.' at the start of the base name
          (this is a change in findutils-4.2.2; see section STANDARDS CON‐
          FORMANCE below).  To ignore a directory and the files under it,
          use -prune; see an example in the description of -path.  Braces
          are not recognised as being special, despite the fact that some
          shells including Bash imbue braces with a special meaning in
          shell patterns.  The filename matching is performed with the use
          of the fnmatch(3) library function.   Don't forget to enclose
          the pattern in quotes in order to protect it from expansion by
          the shell.
于 2013-09-17T15:02:42.247 回答
4
find . -name '*.html'

您必须单引号通配符以防止外壳在传递它以查找时对其进行通配。

于 2013-09-17T15:02:35.183 回答
2

你要

find . -name "*.html"

Find 默认使用 emacs 正则表达式,而不是您可能习惯的 posix。

于 2013-09-17T15:03:57.643 回答
1

你在这里遗漏了几件事。首先是路径。如果您在本地路径中搜索,请使用.例如:find .将递归地列出当前目录中的每个文件和目录。第二个 a*是通配符。因此,要查找.html当前目录中的所有文件,请尝试

find . -name *.html
于 2013-09-17T15:05:19.517 回答