How To Wiki
Advertisement

To display a list of the broken links, replacing ${directory} with the desired root directory[]

find /path/to/search -xtype l
as explained at http://ynform.org/w/Pub/UnixSymbolicLink
for f in $(find /path/to/search -type l); do if [ ! -e "$f" ]; then echo "$f"; fi; done

To display a list of the broken links, with where they link to[]

find -xtype l -exec ls -l {} \;
find /usr/local/bin -type l | while read f; do if [ ! -e "$f" ]; then ls -l "$f"; fi; done
all one line, if there are broken links it will display them with ls -l

To REMOVE the broken links[]

find /path/to/search -xtype l -delete
find -L /path/to/search -type l -delete
find /path/to/search -type l | while read f; do if [ ! -e "$f" ]; then rm -f "$f"; fi; done

None of these methods will detect cyclic links. For information on that, see:

http://ynform.org/w/Pub/FindCommandDetectUnixCyclicSymbolicLink
Advertisement