/dir
,其中包含3个符号链接指向其他目录/dir/dir11
,/dir/dir12
和/dir/dir13
。我想列出dir
中的所有文件,包括dir11
、dir12
和dir13
中的文件。
为了更加通用,我想列出所有文件,包括符号链接目录中的文件。find .
、ls -R
等命令会在符号链接处停止而不会进入这些目录来列出更多内容。/dir
,其中包含3个符号链接指向其他目录/dir/dir11
,/dir/dir12
和/dir/dir13
。我想列出dir
中的所有文件,包括dir11
、dir12
和dir13
中的文件。
为了更加通用,我想列出所有文件,包括符号链接目录中的文件。find .
、ls -R
等命令会在符号链接处停止而不会进入这些目录来列出更多内容。-L
选项可实现您想要的功能,它会解引用符号链接。ls -LR
你也可以使用以下方法来实现此目的
find -follow
-follow
选项会指示 find 命令跟随符号链接到目录。在 Mac OS X 上使用该选项,请执行以下操作:find -L
-follow
已被弃用。
find -L .
。我遇到了和@S.Matthew_English一样的问题。 - fregante那么对于tree呢?tree -l
会跟随符号链接。
免责声明:本人编写了此软件包。
ls
更直观的视图。它也更容易粘贴。 - dhaupintree
不可用,你无法将其添加到你正在尝试探索的系统中。 - thorocfind /dir -type f -follow -print
-type f
表示它将显示实际的文件(而不是符号链接)
-follow
表示它将跟随您的目录符号链接
-print
会导致它显示文件名。
如果您想要类似于ls的显示,可以执行以下操作:
find /dir -type f -follow -print|xargs ls -l
ls -L
选项更漂亮的显示。 - imbr使用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 man页面:
-L Follow symbolic links.
如果你发现你只想要跟随少量的符号链接(比如只是你提到的顶层链接),那么你可以看一下-H选项,它只会跟随你在命令行上传递给它的符号链接。
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
properties of the file to which the link points, not from the link itself (unless it is a broken symbolic link or find is unable to examine the file to which the link points). Use of this option implies -noleaf. If you later use the -P option, -noleaf will still be in effect. If -L is in effect and find discovers a symbolic link to a subdirectory during its search, the subdirectory pointed to by the symbolic link will be searched.
我知道tree
是一个合适的工具,但我没有安装tree
。因此,我在这里找到了一个相似的替代方案here
find ./ | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'
ls -R -L
-L
参数会解除符号链接。这也会使得任何指向文件的符号链接无法被查看,因为它们看起来像是被指向的文件。
如果您想打印所有文件的内容:
find . -type f -exec cat {} +