linux - 使用 linux find 命令查找目录和目录的符号链接(symbolic link)

标签 linux bash shell command find

对于 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/

相关文章:

linux - 为什么这个脚本不能执行另一个脚本

linux - curl 用于获取标题

linux - 如何限制对 Docker 容器中路径的访问?

Bash:如何捕获 set -e,但不退出

linux - 转义 su -c 中的引号

python - 如何使用 bash 脚本结束 django 进程?

c - 在 C 中测试 linux CAP_FOWNER 功能?

linux - 获取使用哪个可执行文件的目录

macos - 如何使用 unix 终端将已安装的 dmg 文件复制到另一个位置?

bash - 我可以在多行命令中使用 $( ... ) 语法吗?