对于 linux 中给定的目录树,我想列出:
- 所有目录,
- 目录的所有符号链接(symbolic link)
- 不是通过符号链接(symbolic link)找到的目录。
考虑一个空目录,然后执行
mkdir a
mkdir a/b
ln -s a c
echo "x" > f1
ln -s f1 f2
然后 找到 . -type d
给出
.
./a
./a/b
因此错过了符号链接(symbolic link) ./c
,而 find 。 -type l
给出
./c
./f2
缺少目录 .
、./a
和 ./a/b
,此外还打印符号链接(symbolic link) ./f2
这不是指向目录的符号链接(symbolic link),而是指向文件的符号链接(symbolic link)。
最佳答案
使用-H
选项:
Cause the file information and file type (see stat(2)) returned for each symbolic link specified on the command line to be those of the file referenced by the link, not the link itself. If the referenced file does not exist, the file information and type will be for the link itself. File information of all symbolic links not on the command line is that of the link itself.
所以:
find -H . -type d
将列出目录和目录链接。
关于linux - 使用 linux find 命令查找目录和目录的符号链接(symbolic link),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20260247/