3

查找 Linux 中的所有符号链接

 1 year ago
source link: https://www.51cto.com/article/746318.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

查找 Linux 中的所有符号链接

作者:Linux迷 2023-02-13 11:26:03
如何找到软链接?您可以使用 ls 命令。一些发行版以不同的颜色显示链接。
e5105df239d1104eeee6006db2aba4b29c6a3f.jpg

如何找到软链接?您可以使用 ls 命令。一些发行版以不同的颜色显示链接。从 ls 获取“长列表”的做法是最常见的,以至于许多发行版将 ll 别名为 ls -l。长列表提供了许多重要的文件属性,例如权限、拥有每个文件的用户、文件所属的组、文件大小(以字节为单位)以及文件上次更改的日期。长列表总是可靠的,因为它显示了与 l 的链接:

lrwxrwxrwx 1 linuxmi linuxmi     13  2月 1日 08:54 xpstat -> expect_xpstat
559ca958438d43d135e724cd9607086d17b18e.png

您还可以使用 tree 命令:

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ tree
8833d4f166c368d36e0963e11e2f08715d2947.png

如果您在当前目录中有几个链接,这没关系。但是,如果您想查看嵌套目录结构或整个系统中的链接怎么办?

在本教程中,我将向您展示完成此任务的两种方法:

  • 使用 find 命令
  • 使用符号链接实用程序

因此,让我们从第一个开始。

使用 find 命令查找符号链接

要使用 find 命令查找符号链接,您可以使用以下命令语法:

find Target_directory -type l

例如,在这里,我在linuxmi目录中搜索可用的符号链接:

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ find linuxmi/ -type l
d36767c9334cbda61a13556ea9c11719d758ea.png

但默认情况下,find 命令会启动递归搜索,如果要将搜索限制在一定深度,则必须使用-maxdepth标志。

所以假设我想将linuxmi目录的搜索限制在 1 级,我将使用以下内容:

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ find linuxmi/ -maxdepth 1 -type l
05624a801a9d71eab111842c683ebd9070a7f7.png

 如果你想要详细的输出,包括文件权限、用户组等,那么你必须将 find 命令与-ls标志配对:

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ find linuxmi -type l -ls
f76322b36224d1ba84a9607e39e4876445afaf.png

如果你想在系统范围内搜索,你可以/在命令中使用。

使用符号链接实用程序查找所有符号链接

这个工具是我在网络实习期间使用的。

但它并没有预装。您可以使用发行版的包管理器安装它。对于 Ubuntu/Debian,使用:

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ sudo apt install symlinks
18d66ca97601a01a5b6869ca858ba8ce8d27cd.png

完成安装后,使用给定的命令结构查找可用的符号链接:

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ symlinks -v linuxmi/
47c7dad27877994e4b7784ad73b8e0c5ad4c9f.png

在这里,该-v选项提供详细的输出。

但默认情况下,符号链接实用程序不会查看子目录。-r使用以下选项启用递归搜索:

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ symlinks -vr linuxmi/
59d67f70376d1fc443d0780a25707d6f42027f.png

输出具有特定条款。让我解释一下:

  • relative表示链接是相对于链接所在的当前工作目录的。
  • other_fs表示链接指示不同的文件系统。
责任编辑:赵宁宁 来源: Linux迷

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK