How to find orphan symbolic links

From Wiki-UX.info
Jump to: navigation, search


Abstract[edit]

This article describes a Postfix Shell script to check for orphan (miss) symbolic links in a file system.

for link in `find <filesystem> -type l`
do
   if [ ! -e $link ]; then echo $(ll $link | tr -s ' ' | cut -d " " -f 9-11) ; fi
done

For example:

# cd /home

# echo "test" > test

# ln -s test test1

# rm test

# for link in `find /home -type l`
do
   if [ ! -e $link ]; then echo $(ll $link | tr -s ' ' | cut -d " " -f 9-11) ; fi
done
/home/test1 -> test

Reference[edit]

Authors[edit]