Reputation: 1933
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
.
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.
Upvotes: 193
Views: 524531
Reputation: 2242
in case you would like to print all file contents:
find . -type f -exec cat {} +
Upvotes: -1
Reputation: 10498
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.
Upvotes: 291
Reputation: 32189
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
Upvotes: 61
Reputation: 1819
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.
Upvotes: 3
Reputation: 144
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.
Upvotes: 5
Reputation: 5356
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/--/ |-/'
Upvotes: 5
Reputation: 4373
How about tree? tree -l
will follow symlinks.
Disclaimer: I wrote this package.
Upvotes: 127
Reputation: 43117
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.
Upvotes: 12