查找到特定目录或其子目录之一的符号链接
有没有一种简单的方法来显示指定路径中是否有任何符号链接指向某个目录或其子目录之一?
Is there an easy way to show whether there are any symlinks in a specified path pointing to a certain directory or one of its children?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种简单而快速的方法,假设您将目标作为绝对路径(
readlink(1)
可能有助于解决这个问题):这会找到所有符号链接(
-type l
)下面的$PATH
链接到名称以$DIR
开头的目录 (-xtype d
)。另一种方法是 O(n*m),因此可能需要很长时间和两天的时间:
第一个
find
列出$DIR
及其所有子目录,然后传递(< code>xargs),一次一个 (-n1
),到第二个find
,它查找源自$PATH
下面的所有符号链接代码>.总而言之:
find(1)
是你的朋友。A simple and fast approach, assuming that you have the target as absolute path (
readlink(1)
may help with that matter):This finds all symlinks (
-type l
) below$PATH
which link to a directory (-xtype d
) with a name starting with$DIR
.Another approach, which is O(n*m) and therefore may take ages and two days:
The first
find
lists$DIR
and all its subdirectories which are then passed (xargs
), one at a time (-n1
), to a secondfind
which looks for all symlinks originating below$PATH
.To sum things up:
find(1)
is your friend.跟进earl给出的答案:
-xtype
在Mac OSX上不起作用,但是可以安全地省略:示例:
Following up on the answer given by earl:
-xtype
does not work on Mac OSX, but can be safely omitted:Example:
查看 fslint 中的 findbl(坏链接)脚本。它可能会给你一些提示:
http://code.google.com/p/fslint/源/浏览/主干/fslint/findbl
Have a look at the findbl (bad links) script in fslint. It might give you some hints:
http://code.google.com/p/fslint/source/browse/trunk/fslint/findbl