Applications often reach each release through a stable path even as the release directories change. On Linux, GNU find can list broken symbolic links in a directory before a deployment or restore relies on them.
A symbolic link stores a pathname even after its target disappears. Linux resolves a relative target from the link’s parent directory, so moving the link on its own can break it.
A target on an unmounted backup volume can appear missing until the volume is available. The scan reflects the mounts and directory access available in the shell that runs it.
Steps to find broken symbolic links in Linux:
- Scan for broken symbolic links as your regular user with your directory’s absolute path in place of
/srv/appinside the single quotes.If the starting path is a symbolic link, use the directory it points to. Single quotes keep path characters such as
$literal. For a path containing an apostrophe, type '\'' in place of that character inside the quoted path.$ find '/srv/app' -xtype l /srv/app/live
GNU
findskips traversal through directory symlinks by default.-xtype llists dangling links. GNU Findutils 4.10 and later can also report link loops. No output from an error-free scan means no matches. Iffindreports a directory access error, the scan is incomplete. - Read the stored target using one reported path in place of
/srv/app/liveinside the single quotes.$ readlink '/srv/app/live' releases/v2
readlinkprints the stored path even if the target is missing. Herereleases/v2points to/srv/app/releases/v2because the link is in/srv/app. - Check whether the target exists using the same link path in place of
/srv/app/liveinside the single quotes.$ stat -L '/srv/app/live'
stat -Lfollows the link and shows file or directory details when it resolves. With the link still in place,No such file or directorymeans a component of the target path is missing, andNot a directorymeans a component needed as a directory is a file. A permission error points to an access problem. An error about too many levels of symbolic links points to a loop or a link chain the system could not follow.