The Dead Pointer Audit
In Ubuntu Linux, symbolic links (symlinks) act as shortcuts to other files. However, if the original target file is deleted or moved, the symlink remains on the filesystem as a “broken” or “dead” pointer. These broken links can cause backup scripts to fail, confuse web servers, and clutter directories. Simply searching for all symlinks using -type l is insufficient, as that returns both healthy and broken links. You must explicitly instruct the search engine to evaluate the mathematical destination of the pointer.
Using the find Command with -xtype l
The Linux find command utilizes the highly specific -xtype l flag to exclusively search for symbolic links that point to a non-existent file.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- To scan the entire
/var/www/directory and return an exact list of every single broken symlink, type the following command exactly: find /var/www/ -xtype l- Press Enter.
Symlink Forensics
The -xtype l flag acts as a deep evaluation filter. When the find algorithm encounters a symlink, it attempts to resolve the destination path. If the destination file exists, the link is considered healthy and is ignored. If the destination resolves to a null path (the file is missing), find flags it as broken and prints it to standard output. System administrators frequently pair this command with the delete operator (find /var/www/ -xtype l -delete) to instantly instantly purge an entire directory tree of dead shortcuts.