find /bin -iname 'sh*' 没有返回任何结果

find /bin -iname 'sh*' 没有返回任何结果

问题是关于find命令的语法

me@222:~$ find /bin -iname 'sh*'

不返回任何结果,而:

me@222:/bin$ find -iname 'sh*'

工作正常

设置信息:使用 Windows 中的 Putty 远程进入 ubuntu 20 LTS。

还:
我想要请求一种语法来正确查看 find 正在做什么。例如,它遍历的文件,它尝试匹配的确切路径或文件名字符串等等。

答案1

在最近的 Ubuntu 系统上,/bin由于/usr/bin用户合并,并且该find命令默认不遵循符号链接。来自man find

   -P     Never follow symbolic links.  This  is  the  default  behaviour.
          When find examines or prints information a file, and the file is
          a symbolic link, the information used shall be  taken  from  the
          properties of the symbolic link itself.

   -L     Follow symbolic links.  [...]

   -H     Do  not  follow symbolic links, except while processing the com‐
          mand line arguments.  When find examines or  prints  information
          about  files, the information used shall be taken from the prop‐
          erties of the symbolic link itself.  The only exception to  this
          behaviour is when a file specified on the command line is a sym‐
          bolic link, and the link can be resolved.  For  that  situation,
          the  information  used is taken from whatever the link points to
          (that is, the link is followed).  The information about the link
          itself  is used as a fallback if the file pointed to by the sym‐
          bolic link cannot be examined.  If -H is in effect  and  one  of
          the  paths specified on the command line is a symbolic link to a
          directory, the contents  of  that  directory  will  be  examined
          (though of course -maxdepth 0 would prevent this).

你可能想要

find -H /bin -iname 'sh*'

或者

find /usr/bin -iname 'sh*'

跟随/bin符号链接但保留其下面的默认行为。

相关内容