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

Re: How to determine if symbolic link is dangling?



Jean Pierre LeJacq:
> 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.

-- 
#!/usr/bin/perl -i=-/*/~%*~%/~~%/~~~-/*/_/=~~~-/====~~! # joey@kite.ml.org
$o=35;$_="$^I-*!=====_!/";s/~/!*/g;s~%~-/ / ~g;$_.='---      Joey Hess
';s/=/__/g;y|*!| \\|;for(split/-/){print' 'x$o--."$_\n"}# a M.C. Escher fan
               "true - do nothing, successfully" - - true (1)


Reply to: