为什么 ls 显示一个不存在的文件?

Nan*_*iao 6 ls directory wildcards

我想列出名称以大写开头的所有文件:

[root@localhost /]# ls /usr/bin/[[:upper:]]*
/usr/bin/AtoB            /usr/bin/GenIssuerAltNameExt   /usr/bin/PKCS12Export
/usr/bin/AuditVerify     /usr/bin/GenSubjectAltNameExt  /usr/bin/POST
/usr/bin/BtoA            /usr/bin/GET                   /usr/bin/PrettyPrintCert
/usr/bin/CMCEnroll       /usr/bin/HEAD                  /usr/bin/PrettyPrintCrl
/usr/bin/CMCRequest      /usr/bin/HtFileType            /usr/bin/RSA_SecurID_getpasswd
/usr/bin/CMCResponse     /usr/bin/HttpClient            /usr/bin/RunSimTest
/usr/bin/CMCRevoke       /usr/bin/IBMgtSim              /usr/bin/TokenInfo
/usr/bin/CRMFPopClient   /usr/bin/Mail                  /usr/bin/X
/usr/bin/ExtJoiner       /usr/bin/OCSPClient            /usr/bin/Xorg
/usr/bin/GenExtKeyUsage  /usr/bin/PKCS10Client
Run Code Online (Sandbox Code Playgroud)

它工作正常,但是当应用到当前文件夹时,它看起来很奇怪:

[root@localhost /]# ls ./[[:upper:]]*
snk321cq
[root@localhost /]# ls -lt snk321cq
ls: cannot access snk321cq: No such file or directory
[root@localhost /]# ls -lt ./snk321cq
ls: cannot access ./snk321cq: No such file or directory
Run Code Online (Sandbox Code Playgroud)

为什么要显示snk321cq?实际上没有这样的文件。

jll*_*gre 15

此文件位于与模式匹配的目录下,请使用:

ls -d ./[[:upper:]]*
Run Code Online (Sandbox Code Playgroud)

默认情况下,当将目录名称作为参数传递时,ls显示其内容,而不是其名称。该-d选项是禁用此功能。

使用该[[:upper:]]*模式时,shell 会将其扩展为每个以大写字母开头的文件名,以便ls接收扩展后的目录名称。