在 CentOS(以及大多数 Linux 发行版)中,查找**软连接(符号链接,symbolic link)**常用以下几种方法:
find 查找软连接(最常用)find /path/to/dir -type l
例子:
find /etc -type l
find / -type l 2>/dev/null
2>/dev/null用于忽略权限不足的错误
find / -type l -lname "*filename*" 2>/dev/null
例如:
find / -type l -lname "*python*" 2>/dev/null
ls 查看是否为软连接ls -l
软连接示例:
lrwxrwxrwx 1 root root 10 test.txt -> /tmp/a.txt
第一个字符是
l,并且有->
readlink 查看软连接指向readlink /path/to/symlink
或:
readlink -f /path/to/symlink
示例:
readlink -f /usr/bin/python
file 命令判断file /path/to/file
示例:
file /usr/bin/python
输出:
/usr/bin/python: symbolic link to `/usr/bin/python2'
find /etc -type l -exec ls -l {} \;
或新版 find:
find /etc -type l -ls
find /path -type l ! -exec test -e {} \; -print
或更简单:
find /path -xtype l
.so 软连接find /usr/lib -type l -name "*.so"
find /usr/bin -type l
| 需求 | 命令 |
|---|---|
| 查找软连接 | find 目录 -type l |
| 查看软连接指向 | readlink -f 文件 |
| 判断是否软连接 | ls -l |
| 查找断链 | find 目录 -xtype l |
如果你有具体路径或场景(比如:查找 Java、Python、Nginx 的软连接),可以告诉我,我可以给你更精确的命令。