gpt4 book ai didi

regex - Unix - 使用 find 列出所有 .html 文件。 (不要使用 shell 通配符或 ls 命令)

转载 作者:行者123 更新时间:2023-12-02 06:02:15 26 4
gpt4 key购买 nike

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

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

最佳答案

你需要的是

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.

关于regex - Unix - 使用 find 列出所有 .html 文件。 (不要使用 shell 通配符或 ls 命令),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18853285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com