为什么 find exec ls 停止显示其中一个文件?

ile*_*ras 0 linux shell bash find

我有一个 find + ls 向我展示了几个文件的 .sh 和 .sh.bak 。

我复制了其中一个,以为我会有 3 个文件,但是,
ls 停止显示其中一个,即 .sh.bak

我正在重复历史中的 find + ls 并且我已经比较了副本

查看2个文件:

[root@localhost jeos]# find / -name del-non-*-locales.sh* -execdir ls -lh {} \;  
-rwxr-xr-x. 1 root root 4.4K Dec 17  2016 /root/proj/vm/locale/backups/del-non-eng-locales.sh.bak  
-rwxr-xr-x. 1 root root 4.4K Dec 17  2016 /root/proj/host.setup/manual/del-non-english-locales.sh  
Run Code Online (Sandbox Code Playgroud)

复制 1

[root@localhost jeos]# cp ~/proj/host.setup/manual/del-non-english-locales.sh .
Run Code Online (Sandbox Code Playgroud)

向上箭头 + 输入...以为我现在会看到 3 个文件

[root@localhost jeos]# find / -name del-non-*-locales.sh* -execdir ls -lh {} \;  
-rwxr-xr-x. 1 root root 4.4K Dec 17  2016 /root/proj/host.setup/manual/del-non-english-locales.sh  
-rwxr-xr-x. 1 root root 4.4K Nov  9 11:05 /root/proj/jeos/del-non-english-locales.sh
Run Code Online (Sandbox Code Playgroud)

find + ls 没有改变,它退出显示的文件在这里:

[root@localhost jeos]# ls -lh /root/proj/vm/locale/backups/del-non-eng-locales.sh.bak  
-rwxr-xr-x. 1 root root 4.4K Dec 17  2016 /root/proj/vm/locale/backups/del-non-eng-locales.sh.bak
Run Code Online (Sandbox Code Playgroud)

Sat*_*ura 7

你需要报价del-non-*-locales.sh*

第一次运行有效,因为当前目录中没有任何文件匹配del-non-*-locales.sh*,因此默认情况下模式扩展到自身(带有星号和所有)。

复制~/proj/host.setup/manual/del-non-english-locales.sh到当前目录后,del-non-*-locales.sh*扩展为del-non-english-locales.sh,因此您实际上是在搜索该确切名称,而不是del-non-*-locales.sh*. 这就是为什么del-non-eng-locales.sh.bak不再匹配的原因。