【发布时间】:2019-07-08 19:20:22
【问题描述】:
我有以下文件夹:
- 文件夹 A
- 文件夹 B(它是文件夹 A 的符号链接)
问题是当我访问文件夹 B 时,我可以无限深入(即文件夹 A > 文件夹 B > 文件夹 B > 文件夹 B),因为文件夹 B 在文件夹 A 内。
通过文件夹 A 访问后,有什么方法可以忽略文件夹 B 吗?
非常感谢!
【问题讨论】:
我有以下文件夹:
问题是当我访问文件夹 B 时,我可以无限深入(即文件夹 A > 文件夹 B > 文件夹 B > 文件夹 B),因为文件夹 B 在文件夹 A 内。
通过文件夹 A 访问后,有什么方法可以忽略文件夹 B 吗?
非常感谢!
【问题讨论】:
find 命令检测符号链接循环并将打印一条警告消息,而不是重复遍历它们。例如,使用 -L 选项跟随符号链接可能会打印此警告:
$ find -L /some/path
find: File system loop detected; `/some/path/link' is part of the same file system loop as `/some/path'.
来自手册页:
The find utility shall detect infinite loops; that is,
entering a previously visited directory that is an ancestor of
the last file encountered. When it detects an infinite loop,
find shall write a diagnostic message to standard error and
shall either recover its position in the hierarchy or
terminate.
【讨论】:
致所有查看这里的程序员(命令行工具问题应转至 unix.stackexchange.com):
您应该知道,Linux/BSD 函数 fts_open() 为您提供了一个易于使用的迭代器,用于遍历所有子目录内容,同时还检测此类符号链接递归。
大多数命令行工具都使用此功能来为它们处理这种情况。那些不经常遇到符号链接递归问题的人,因为“手动”这样做很困难(任何知道它的人都应该改用上述函数)。
【讨论】: