Gentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc


Quick Start

Code: (Bash)
find . -type l | (while read FN ; do test -e "$FN" || ls -ld "$FN"; done)
Code: (Just using findutil and test)
find / -type l ! -exec test -r {} \; -print

Code: (Just "find")
find -L . -type l


The find command finds all symbolic links in the current directory, “.”, and writes their names to its standard output. That gets piped into the parenthesized while loop, which tests each link. If the link points to an existing file, nothing happens, but if the link's target does not exist, the ls command gets executed and detailed information about the link and its intended target are sent to the standard output.


Sometimes emerge fails when there are broken links in system directories. To find broken links in the system directory /usr, give yourself root access and then issue this related command:

Code: (Bash)
find /usr -type l | (while read FN ; do test -e "$FN" || ls -ld "$FN"; done)

Another directory where broken links can be a problem is /var.

Alternate using symlinks and qfile.

Code: (install prerequsites)
emerge -uav app-portage/portage-utils app-misc/symlinks

Find all dangling symlinks:

Code: (Bash)
symlinks -rv / | grep "dangling:" | awk '{print $2}' | sort

Find all dangling symlinks and what package (if any) owns them.

Code: (Bash)
symlinks -rv / | grep "dangling:" | awk '{print $2}' | xargs qfile | sort

Both in a script with error checking:

Code: (Shellscript)


RD=$'\x1b[31;01m' Rd=$'\x1b[00;31m'
GR=$'\x1b[32;01m' Gr=$'\x1b[00;32m'
YL=$'\x1b[33;01m' Yl=$'\x1b[00;33m'
BL=$'\x1b[34;01m' Bl=$'\x1b[00;34m'
FC=$'\x1b[35;01m' Fc=$'\x1b[00;35m'
CY=$'\x1b[36;01m' Cy=$'\x1b[00;36m'

        echo ""

        # check to see if /usr/bin/symlinks exists.
        if [[ ! -f $SYMLNBIN ]]; then
                echo ${RD}"Please emerge: ${BL} (app-misc/symlinks)"${NO}

        # check to see if /usr/bin/qfile exists.
        if [[ ! -f "$QFILEBIN" ]]; then
                echo ${RD}"Please emerge: ${BL} (app-portage/portage-utils)"${NO}

        echo ${RD} "Dangling symlinks found:"${NO}
        echo ""
        symlinks -rv / | grep "dangling:" | awk '{print $2}' | sort

        echo ""
        echo ${YL} "Packages owning dangling symlinks:"${NO}
        echo ""
        symlinks -rv / | grep "dangling:" | awk '{print $2}' | xargs qfile | sort
        echo ""

Retrieved from ""

Last modified: Sat, 01 Dec 2007 20:10:00 +0000 Hits: 8,017