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

后端 未结 8 906
甜味超标
甜味超标 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:12

    in case you would like to print all file contents: find . -type f -exec cat {} +

    0 讨论(0)
  • 2020-12-07 08:13

    The -L option to ls will accomplish what you want. It dereferences symbolic links.

    So your command would be:

    ls -LR
    

    You can also accomplish this with

    find -follow
    

    The -follow option directs find to follow symbolic links to directories.

    On Mac OS X use

    find -L
    

    as -follow has been deprecated.

    0 讨论(0)
  • 2020-12-07 08:20
    ls -R -L
    

    -L dereferences symbolic links. This will also make it impossible to see any symlinks to files, though - they'll look like the pointed-to file.

    0 讨论(0)
  • 2020-12-07 08:24
    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
    

    properties of the file to which the link points, not from the link itself (unless it is a broken symbolic link or find is unable to examine the file to which the link points). Use of this option implies -noleaf. If you later use the -P option, -noleaf will still be in effect. If -L is in effect and find discovers a symbolic link to a subdirectory during its search, the subdirectory pointed to by the symbolic link will be searched.

    0 讨论(0)
  • 2020-12-07 08:30

    How about tree? tree -l will follow symlinks.

    Disclaimer: I wrote this package.

    0 讨论(0)
  • 2020-12-07 08:30

    I knew tree was an appropriate, but I didn't have tree installed. So, I got a pretty close alternate here

    find ./ | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'
    
    0 讨论(0)
提交回复
热议问题