如何查找并列出为特定文件创建的所有符号链接?

Avi*_*Raj 55 command-line symbolic-link

我在特定文件或目录的各种路径上创建了许多符号链接。我想要创建的符号链接路径(位置)的整个列表。

例子:

我为~/Pictures许多目录上的目录创建了符号链接。如何列出该~/Pictures目录的所有符号链接?

那可能吗?如果是,那么如何?

Rad*_*anu 46

下面是一个例子:

find -L /dir/to/start -xtype l -samefile ~/Pictures
Run Code Online (Sandbox Code Playgroud)

或者,也许更好:

find -L /dir/to/start -xtype l -samefile ~/Pictures 2>/dev/null
Run Code Online (Sandbox Code Playgroud)

摆脱一些错误的一样Permission deniedToo many levels of symbolic links或者File system loop detectedfind抛出他们时,没有正确的权限或其他情况。

  • -L - 按照符号链接。

  • -xtype l - 文件是符号链接

  • -samefile name- 文件与name. 当-L生效时,这可以包括符号链接。

笔记:

  • 在 中使用小写 L -xtype l,而不是数字 1。
  • 在 macOS / Darwin 上,-xtype-type.


Abd*_*UMI 8

很简单,使用选项-lname

find / -lname /path/to/original/dir
Run Code Online (Sandbox Code Playgroud)

来自man find

-lname pattern
       File is a symbolic link whose contents match shell pattern pattern.  The
       metacharacters do not treat `/' or `.' specially.  If the -L option or the
       -follow option is in effect, this test returns false unless the symbolic link
       is broken.
Run Code Online (Sandbox Code Playgroud)

注意:请记住,符号链接可以在任何地方,包括远程系统(如果您正在共享文件),因此您可能无法找到它们。