Wikia

How To Wiki

How to find broken symbolic links

1,794pages on
this wiki
Talk0

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

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 Edit

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 Edit

find /path/to/search -xtype l -delete
find -L /path/to/search-type l -delete
find /path/do/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

Around Wikia's network

Random Wiki