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.

  1. Scan for broken symbolic links as your regular user with your directory’s absolute path in place of /srv/app inside 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 find skips traversal through directory symlinks by default. -xtype l lists dangling links. GNU Findutils 4.10 and later can also report link loops. No output from an error-free scan means no matches. If find reports a directory access error, the scan is incomplete.

  2. Read the stored target using one reported path in place of /srv/app/live inside the single quotes.
    $ readlink '/srv/app/live'
    releases/v2

    readlink prints the stored path even if the target is missing. Here releases/v2 points to /srv/app/releases/v2 because the link is in /srv/app.

  3. Check whether the target exists using the same link path in place of /srv/app/live inside the single quotes.
    $ stat -L '/srv/app/live'

    stat -L follows the link and shows file or directory details when it resolves. With the link still in place, No such file or directory means a component of the target path is missing, and Not a directory means 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.

Share this guide