将 find 与 -L 选项一起使用

发布于 2025-01-03 18:46:50 字数 431 浏览 3 评论 0原文

我有这个:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月亮邮递员 2025-01-10 18:46:50

该名称不是文件的属性,而是包含该文件的目录的属性。

如果要匹配符号链接的内容,请使用 -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.

挽梦忆笙歌 2025-01-10 18:46:50

当存在目录链接时,适用“链接跟踪”。

文件的链接只是一个需要查找的文件本身。如果没有 -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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文