tags:

views:

6366

answers:

5

Suppose i have a directory /dir inside which there are 3 symlinks to other directories /dir/dir11, /dir/dir12 , /dir/dir13 etc., 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.

+10  A: 

The -L option to ls will accomplish what you want. It deferences 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.

Michael Ridley
-follow is deprecated in favor of -L in newer versions of find.
pjz
'deferences' should be 'dereferences' in the first line of an otherwise admirably succinct answer.
Jonathan Leffler
@pjz: is there a cross-reference for '-follow deprecated; use -L'? Somewhat to my considerable surprise, I did find '-L' and '-H' listed in the POSIX / SUS standard at http://www.opengroup.org/onlinepubs/009695399/toc.htm, and even more to my surprise no '-follow', so I answered my own question.
Jonathan Leffler
A: 

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.

pjz
A: 
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
dvorak
A: 

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.

Branan
+1  A: 

Hope I don't get down-modded for recommending a program I wrote, but how about tree? tree -l will follow symlinks. You may already have it, but you can download it here:

http://mama.indstate.edu/users/ice/tree/

Steve Baker