[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to determine if symbolic link is dangling?



Joey Hess <joey@kite.ml.org> writes:

> > I'm trying to complete the next release of wn and have run
> > into a problem.  I need to recurse through /usr/doc and find
> > all the (sub)directories.  I want to be able to support
> > symbolic links to directories outside /usr/doc hierarchy.
> > Unfortunately there will be dangling symbolic links.
> > 
> > I'm using the "find" utility to recurse through the
> > directory hierarchy.  Is there a way to test if the link is
> > dangling?
> 
> I'm not sure what language you're using, but C and perl have a readlink()
> function that returns the file tha link is pointing too. Then you just have
> to check if that file exists.

Easier is to just stat the file.  One less system call.

find . -type l | perl -ne 'chop; print "$_\n" if (!stat)'

will print all danglinks links.


Guy


Reply to: