递归列出目录中的所有文件,包括symlink目录中的文件 [英] Recursively list all files in a directory including files in symlink directories

查看:83
本文介绍了递归列出目录中的所有文件,包括symlink目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆