查找到特定目录或其子目录之一的符号链接

发布于 2024-08-14 05:45:10 字数 67 浏览 1 评论 0原文

有没有一种简单的方法来显示指定路径中是​​否有任何符号链接指向某个目录或其子目录之一?

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

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

发布评论

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

评论(3

流年已逝 2024-08-21 05:45:10

一种简单而快速的方法,假设您将目标作为绝对路径(readlink(1) 可能有助于解决这个问题):

find $PATH -type l -xtype d -lname "$DIR*"

这会找到所有符号链接(-type l)下面的 $PATH 链接到名称以 $DIR 开头的目录 (-xtype d)。


另一种方法是 O(n*m),因此可能需要很长时间和两天的时间:

find $DIR -type d | xargs -n1 find $PATH -lname

第一个 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):

find $PATH -type l -xtype d -lname "$DIR*"

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:

find $DIR -type d | xargs -n1 find $PATH -lname

The first find lists $DIR and all its subdirectories which are then passed (xargs), one at a time (-n1), to a second find which looks for all symlinks originating below $PATH.


To sum things up: find(1) is your friend.

吃颗糖壮壮胆 2024-08-21 05:45:10

跟进earl给出的答案

-xtype在Mac OSX上不起作用,但是可以安全地省略:

find $PATH -type l -lname "$DIR*"

示例:

find ~/ -type l -lname "~/my/sub/folder/*"

Following up on the answer given by earl:

-xtype does not work on Mac OSX, but can be safely omitted:

find $PATH -type l -lname "$DIR*"

Example:

find ~/ -type l -lname "~/my/sub/folder/*"
眼眸里的那抹悲凉 2024-08-21 05:45:10

查看 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

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