Recursively list all files in a directory including files in symlink directories

后端 未结 8 907
甜味超标
甜味超标 2020-12-07 07:46

Suppose I have a directory /dir inside which there are 3 symlinks to other directories /dir/dir11, /dir/dir12, and /dir/dir13

相关标签:
8条回答
  • 2020-12-07 08:31
    find /dir -type f -follow -print
    

    -type f means it will display real files (not symlinks)

    -follow means it will follow your directory symlinks

    -print will cause it to display the filenames.

    If you want a ls type display, you can do the following

    find /dir -type f -follow -print|xargs ls -l
    
    0 讨论(0)
  • 2020-12-07 08:34

    Using ls:

      ls -LR
    

    from '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
    

    Or, using find:

    find -L .
    

    From the find manpage:

    -L     Follow symbolic links.
    

    If you find you want to only follow a few symbolic links (like maybe just the toplevel ones you mentioned), you should look at the -H option, which only follows symlinks that you pass to it on the commandline.

    0 讨论(0)
提交回复
热议问题