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

Cur*_*awg 133 linux

假设我有一个目录/dir中,其中有3个符号连接其他目录 /dir/dir11,/dir/dir12/dir/dir13.我想列出dir包含其中的所有文件dir11,dir12dir13.

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

Mic*_*ley 210

可以完成你想要的-L选项ls.它取消引用符号链接.

所以你的命令是:

ls -LR
Run Code Online (Sandbox Code Playgroud)

你也可以用它完成这个

find -follow
Run Code Online (Sandbox Code Playgroud)

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

在Mac OS X上使用

find -L
Run Code Online (Sandbox Code Playgroud)

-follow已被弃用.

  • 在较新版本的find中,不推荐使用-follow以支持-L. (13认同)
  • 在OS X 10.10上,这有效:`find -L .` - 我和@ S.Matthew_English有同样的问题 (4认同)

Ste*_*ker 114

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

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

  • 赞成写作和提供很酷的软件:) (52认同)
  • 拱包怎么样? (2认同)

dvo*_*rak 44

find /dir -type f -follow -print
Run Code Online (Sandbox Code Playgroud)

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

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

-print 将使它显示文件名.

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

find /dir -type f -follow -print|xargs ls -l
Run Code Online (Sandbox Code Playgroud)


pjz*_*pjz 8

使用ls:

  ls -LR
Run Code Online (Sandbox Code Playgroud)

来自'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
Run Code Online (Sandbox Code Playgroud)

或者,使用find:

find -L .
Run Code Online (Sandbox Code Playgroud)

从查找联机帮助页:

-L     Follow symbolic links.
Run Code Online (Sandbox Code Playgroud)

如果你发现你只想遵循一些符号链接(比如你刚才提到的那些符号链接),你应该看一下-H选项,它只跟随你在命令行上传递给它的符号链接.


小智 5

find -L /var/www/ -type l

# man find
Run Code Online (Sandbox Code Playgroud)
-L     Follow  symbolic links.  When find examines or prints information about files, the information used shall be taken from the
Run Code Online (Sandbox Code Playgroud)

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


div*_*gon 5

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

find ./ | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'
Run Code Online (Sandbox Code Playgroud)