查找 Linux 中的所有符号链接
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 中的所有符号链接
如何找到软链接?您可以使用 ls 命令。一些发行版以不同的颜色显示链接。从 ls 获取“长列表”的做法是最常见的,以至于许多发行版将 ll 别名为 ls -l。长列表提供了许多重要的文件属性,例如权限、拥有每个文件的用户、文件所属的组、文件大小(以字节为单位)以及文件上次更改的日期。长列表总是可靠的,因为它显示了与 l 的链接:
lrwxrwxrwx 1 linuxmi linuxmi 13 2月 1日 08:54 xpstat -> expect_xpstat
您还可以使用 tree 命令:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ tree
如果您在当前目录中有几个链接,这没关系。但是,如果您想查看嵌套目录结构或整个系统中的链接怎么办?
在本教程中,我将向您展示完成此任务的两种方法:
- 使用 find 命令
- 使用符号链接实用程序
因此,让我们从第一个开始。
使用 find 命令查找符号链接
要使用 find 命令查找符号链接,您可以使用以下命令语法:
find Target_directory -type l
例如,在这里,我在linuxmi目录中搜索可用的符号链接:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ find linuxmi/ -type l
但默认情况下,find 命令会启动递归搜索,如果要将搜索限制在一定深度,则必须使用-maxdepth标志。
所以假设我想将linuxmi目录的搜索限制在 1 级,我将使用以下内容:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ find linuxmi/ -maxdepth 1 -type l
如果你想要详细的输出,包括文件权限、用户组等,那么你必须将 find 命令与-ls标志配对:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ find linuxmi -type l -ls
如果你想在系统范围内搜索,你可以/在命令中使用。
使用符号链接实用程序查找所有符号链接
这个工具是我在网络实习期间使用的。
但它并没有预装。您可以使用发行版的包管理器安装它。对于 Ubuntu/Debian,使用:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ sudo apt install symlinks
完成安装后,使用给定的命令结构查找可用的符号链接:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ symlinks -v linuxmi/
在这里,该-v选项提供详细的输出。
但默认情况下,符号链接实用程序不会查看子目录。-r使用以下选项启用递归搜索:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ symlinks -vr linuxmi/
输出具有特定条款。让我解释一下:
- relative表示链接是相对于链接所在的当前工作目录的。
- other_fs表示链接指示不同的文件系统。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK