Think of them as the Linux equivalent of a Windows shortcut. Symbolic links (symlinks) are special files that serve as pointers to the actual file or directory location on the system.
For example, in Windows, if we have a text file named ‘xyz.txt’ under the Documents folder in the C: drive, and we create a shortcut to it on the desktop, we’re not creating a copy of the file. Instead, we’re creating a pointer (shortcut) that automatically opens the file from its original location whenever we access it.
Why find and remove symlinks?
If you create a symlink to a file and later delete the original file, the symlink remains but is unable to point to its target location.
For effective system maintenance, it’s critical to identify and remove these broken, unused, or redundant symlinks. Doing so offers several benefits:
- Prevents confusion: It stops users or scripts from encountering outdated or incorrect paths, avoiding errors and uncertainty.
- Maintains integrity: In large or complex systems, old symlinks can lead to misconfigurations or operational errors, making removal essential for system stability.
- Keeps directories clean: It helps keep your file structure organized and clutter-free by removing unnecessary pointers.
Find all the symlinks
This method shows you how to find all the symlinks in a specific directory and its subdirectories. In Linux, the commands are case sensitive and must be inputted properly. Let’s take an example of ‘Document’ directory.
- First open the Terminal by using (Ctrl + Alt + T).

- To find all the symlinks in document directory, type the below command to enter the document directory and press enter.
cd Document

3. Once you enter the directory type the following command and again press enter.

Here’s what it does, step by step:
- find > This is the Unix/Linux command used to search for files and directories.
- . > The dot means “start searching in the current directory”.
- -type l → This option tells find to look for symbolic links (symlinks). In find, the letter l stands for “link.”
- Then it will show the symlinks under the document directory as shown below.

That’s it! Now you know how to see the symlinks in a directory.
Find symlinks with conditions
The command shown above displays a list of all the symbolic links, broken or not, that point to directories or files. If you wish to find the symlinks separately, use the below command with different conditions. Execute the below commands on Terminal.
- Find broken symlinks (pointing to nonexistent targets)
find /path/to/directory -type l ! -exec test -e {} \; -print
Here’s what it does, step by step:
a. find /path/to/directory : A placeholder or path for the actual directory you want to search in.
b. -type l : Only look for symbolic links.
c. ! -exec test -e {} \; : The ! sign means NOT.
d. -exec test -e {} : checks if the symlink’s target exists.
e. So ! -exec test -e {} matches symlinks whose targets do not exist (broken symlinks).
f. -print : Print the paths of the symlinks that match the conditions.
2. Find symlinks pointing to directories
find /path/to/directory -type l -exec test -d {} \; -print
Here’s what it does:
Adding: -exec test -d {} \; → finds symlinks pointing to directories.
- Find symlinks pointing to files find /path/to/directory -type l -exec test -f {} \; -print
Here’s what it does:
Adding: -exec test -f {} \; → finds symlinks pointing to files.
Removing symlinks
In Linux, you can use two different commands to remove the symlinks: rm and unlink. Both serve the same purpose: deleting the link itself. But they differ slightly in how they’re used. Execute the below commands on Terminal.
Note: Neither of the following two commands delete the original file, they only delete the symlinks.
unlink: Removes a single symlink or file at a time.
Syntax:
unlink symlink_name
For our example, we are using a symlink named mylink. After writing the command, simply press enter and it will remove the symlink.
Input: unlink mylink

rm: This command can remove multiple symlinks or files at a time. Here is the syntax to be used and the variations that we can use with this command to make its use more flexible.
rm symlink_name
In case if you have one symlink named mylink, the input will be as shown below. After writing the command, simply press enter and it will remove the symlink.
Input: rm mylink

In case you have multiple symlinks, let’s say named mylink and mylink1, the input will be as shown below. After writing the command, simply press enter, and it will remove the symlinks.
Input: rm mylink mylink1

Below are the variations that are used with command rm.
- To force delete
Syntax:
rm -f mylink

- To delete with confirmation
Syntax:
rm -i mylink

Asks before deleting each file or symlink.
- To delete recursively
Synatx:
rm -r folder

Delete folder and its contents.
- To use it on a symlink
Syntax:
rm -r mylink

- To show deleted Items (Verbos)
Syntax:
rm -v mylink

Prints the name of each file or link removed.
- Recursive + force
Syntax:
rm -rf folder

Delete everything inside the folder without asking.
Finding symlinks and removing them can be challenging. With our step-by-step guide, we hope you can easily understand the process and maintain your data integrity.














