递归地列出一个目录中的所有文件,包括符号链接目录中的文件

假设我有一个目录 /dir,其中有3个到其他目录的符号链接 /dir/dir11/dir/dir12,和 /dir/dir13。我想列出所有的文件在 dir包括在 dir11dir12dir13

为了更通用,我想列出所有的文件,包括目录中的符号链接。find .ls -R等在符号链接处停止,而不进入它们以进一步列出。

487252 次浏览

ls-L选项将完成您想要的操作。它取消了对符号链接的引用。

所以你的命令是:

ls -LR

您也可以使用

find -follow

-follow选项指示 find 跟随指向目录的符号链接。

在 Mac OS X 上使用

find -L

因为 -follow已被废弃。

使用 ls:

  ls -LR

来自“ man ls”:

   -L, --dereference
when showing file information for a symbolic link, show informa‐
tion  for  the file the link references rather than for the link
itself

或者,使用 find:

find -L .

来自 find 手册:

-L     Follow symbolic links.

如果您发现只想跟随 很少符号链接(比如您提到的顶级链接) ,那么应该查看-H 选项,它只跟随您在命令行上传递给它的符号链接。

find /dir -type f -follow -print

-type f意味着它将显示真正的文件(而不是符号链接)

-follow表示它将跟随您的目录符号链接

-print将导致它显示文件名。

如果希望显示 ls 类型,可以执行以下操作

find /dir -type f -follow -print|xargs ls -l
ls -R -L

-L取消引用符号链接。这也使得不可能看到任何指向文件的符号链接,尽管它们看起来像指向文件。

怎么样? tree -l将遵循符号链接。

免责声明 : 我编写了这个包。

find -L /var/www/ -type l


# man find
-L     Follow  symbolic links.  When find examines or prints information about files, the information used shall be taken from the

财产 链接所指向的文件,而不是链接本身(除非它是一个破碎的符号链接或 find 无法 检查文件以 链接所指向的地方)。使用这个选项意味着-noleaf。如果您稍后使用-P 选项,-noleaf 将仍然有效。如果-L 是 实际上,find 在搜索过程中发现一个指向子目录的符号链接,该子目录由 符号链接将 被搜查。

我知道 tree是合适的,但是我没有安装树。所以,我得到了一个非常接近的 给你替代品

find ./ | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'

如果您想打印所有文件 内容: find . -type f -exec cat {} +