将 find 与 -L 选项一起使用
我有这个:
mylink -> myfile
当我这样做时:
find -L . -name 'mylink'
我得到:
./mylink
我不明白为什么会这样,从手册页来看:
-L :遵循符号链接。当 find 检查或打印有关文件的信息时,所使用的信息应从链接指向的文件的属性中获取,而不是从链接本身获取(除非它是损坏的符号链接或 find 无法检查该文件链接指向的位置)。
基于上述内容,我期望示例案例出现以下行为:find 开始搜索。它遇到 mylink。由于 -L 有效,因此它取消引用它并获取指向文件“myfile”的名称。文件名与模式“mylink”不匹配,并且未报告任何内容。发生什么事了?
I have this:
mylink -> myfile
When I do:
find -L . -name 'mylink'
I get:
./mylink
I don't understand why this is so, given this from the man page:
-L : Follow symbolic links. When find examines or prints information about files, the information used shall be taken from the properties of the file to which the link points, not from the link itself (unless it is a bro- ken symbolic link or find is unable to examine the file to which the link points).
Based on the above I was expecting the following behavior for my example case: find starts the search. It encounters mylink. Since -L is in effect it dereferences it and gets the name of the pointed to file 'myfile'. The file name does not match the pattern 'mylink' and nothing is reported. Whats happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该名称不是文件的属性,而是包含该文件的目录的属性。
如果要匹配符号链接的内容,请使用
-lname
。The name is not a property of the file, it's a property of the directory containing it.
If you want to match the contents of a symlink, use
-lname
.当存在目录链接时,适用“链接跟踪”。
文件的链接只是一个需要查找的文件本身。如果没有
-L
,目录的链接也只是一个文件。仅当添加
-L
时,才会递归到链接到的目录中The 'following of links' applies when there is a link to a directory.
A link to a file is just a file itself, to find. Without
-L
a link to a directory is also just a file.Only when
-L
is added, will find recurse into the linked-to directory