递归列出目录中的所有文件,包括symlink目录中的文件 [英] Recursively list all files in a directory including files in symlink directories
问题描述
假设我有一个目录/dir
,其中有3个指向其他目录的符号链接
/dir/dir11
,/dir/dir12
和/dir/dir13
.我想列出dir
中的所有文件,包括dir11
,dir12
和dir13
中的文件.
Suppose I have a directory /dir
inside which there are 3 symlinks to other directories
/dir/dir11
, /dir/dir12
, and /dir/dir13
. I want to list all the files in dir
including the ones in dir11
, dir12
and dir13
.
为了更通用,我想列出所有文件,包括目录中的符号链接文件. find .
,ls -R
等在符号链接处停止,而没有导航到它们以进一步列出.
To be more generic, I want to list all files including the ones in the directories which are symlinks. find .
, ls -R
, etc stop at the symlink without navigating into them to list further.
推荐答案
ls
的-L
选项将完成您想要的操作.它取消引用符号链接.
The -L
option to ls
will accomplish what you want. It dereferences symbolic links.
所以您的命令将是:
ls -LR
您也可以通过以下方式完成此操作
You can also accomplish this with
find -follow
-follow
选项可指导find跟随指向目录的符号链接.
The -follow
option directs find to follow symbolic links to directories.
在Mac OS X上使用
On Mac OS X use
find -L
因为-follow
已被弃用.
这篇关于递归列出目录中的所有文件,包括symlink目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!