[lug] "find" question

Daniel Webb lists at danielwebb.us
Tue Aug 17 11:13:44 MDT 2004


On Tue, 17 Aug 2004, David Morris wrote:

> I could be wrong, but it sounds like what you are trying to
> do is find files in a symbolically linked directory tree
> which are *not* symbolic links themselves.
>
> If that is correct, this is fairly easy to do combined with
> grep and awk (all one line, but too long for email):
>
>     find . -follow -type -f \
>         -exec ls -l {} \; | grep -v ^l | awk '{print $9}'
>
> Or, if you wanted to find *only* symbolic links to files,
> just drop '-v' from the grep statement and leave everything
> else the same.
>
> Note that while you can put the pipe to grep and awk within
> the exec statement (which ends with '\;'), though with a bit
> of difficulty, you don't really want to do that as it'd be
> much slower.  `ls`, though, must be inside the -exec
> statement to avoid a command-line that is too long when
> searching large directory structures.

That makes sense, although I like my "-follow-dir" addition to find better
:)

What if the filenames have spaces in them?  I looked at the documentation
I have for awk, but didn't see anything for multiple fields.  I thought
of:

find . -follow -type -f \
       -exec ls -l {} \; | grep -v ^l | sed 's/  / /g' \
       cut --delimiter=' ' --fields=9-

but that will mess up files with multiple spaces in them.

Any suggestions for that case?

Daniel




More information about the LUG mailing list