How to Find Symlinks to a Specific File in Ubuntu Linux

The Missing Target Problem

In Ubuntu Linux, symbolic links (symlinks) are heavily used by developers to point multiple applications to a single, centralized configuration file. However, if you are planning to move or completely delete a sensitive file (such as a database credential file), you must absolutely verify that no other symlinks on the server are secretly pointing to it. If you delete the file without realizing a background service relies on a symlink pointing to it, the service will crash violently. You must instruct the Linux search engine to trace the destination of every link on the drive.

Using the find Command with -lname

The Linux find command utilizes the highly specific -lname flag to search the filesystem not for the name of the link itself, but strictly for the exact text of the destination the link points toward.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search the entire /var/www/ directory for any symlinks that point specifically to a file named “config.php”, type the following command exactly:
  3. sudo find /var/www/ -type l -lname "*config.php"
  4. Press Enter and provide your administrator password.

Wildcard Protection

The asterisk (*) wildcard before the filename is critical. Because symlinks can be created using absolute paths (e.g., /var/www/html/config.php) or relative paths (e.g., ../config.php), placing the wildcard at the front ensures the command will catch the symlink regardless of how the developer originally typed the path, guaranteeing you do not miss any hidden dependencies before you delete the file.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.