繁体   English   中英

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

[英]Recursively list all files in a directory including files in symlink directories

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

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

ls-L选项将完成您想要的任务。 它取消引用符号链接。

所以你的命令是:

ls -LR

你也可以用它完成这个

find -follow

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

在Mac OS X上使用

find -L

as -follow已被弃用。

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

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

find /dir -type f -follow -print

-type f表示它将显示真实文件(不是符号链接)

-follow意味着它将遵循您的目录符号链接

-print将使其显示文件名。

如果需要ls类型显示,可以执行以下操作

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

使用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 .

从查找联机帮助页:

-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 

链接指向的文件的属性,而不是链接本身的属性(除非它是一个损坏的符号链接或查找无法检查链接指向的文件)。 使用此选项意味着-noleaf。 如果稍后使用-P选项,-noleaf仍然有效。 如果-L生效且find在搜索期间发现指向子目录的符号链接,则将搜索符号链接指向的子目录。

我知道tree是合适的,但我没有安装树。 所以,我在这里有一个非常接近的候补

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

-L取消引用符号链接。 这也使得无法看到文件的任何符号链接 - 它们看起来像指向文件。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM