Find Broken Symbolic Links

Sometimes, a link file may stop working if the original file or folder it points to gets moved, deleted, or becomes unavailable (like if a server goes offline). However, the system does not automatically remove these broken link files.

To find and locate the link files that are not working anymore, you can use the following Command.

Command :

find [folder path] -type l ! -exec test -e {} \; -print

Replace [folder path] with the location where you want to look for broken links. For example, use the (~) symbol to search in your home folder.

Command :

find ~ -type l ! -exec test -e {} \; -print

Output :

Find Broken Symlink

This command will show you a list of all the link files in your home folder that are broken and not working properly anymore.

How to Use ln Command to Create Symbolic Links in Linux

A symbolic link (symlink) is like a shortcut that points to a file or folder on Linux and other similar operating systems. Symlinks can be useful for organizing files and folders, or for making it easier to access files from different locations.

In this guide, you’ll learn how to create symbolic links in Linux using the ‘ln’ command.

Use ln Command to Create Symbolic Links in Linux

  • What Is a Symlink (Symbolic Link)?
  • How to Create Symbolic Link in Linux (ln Command)
  • Create Symlink for Directory
  • Overwrite Symbolic Links
  • Find Broken Symbolic Links
  • Remove Symbolic Links

Similar Reads

What Is a Symlink (Symbolic Link)?

A symlink is a special file that contains the location (path) of another file or folder. This other file or folder is called the “target”. When you try to access the symlink, the operating system automatically looks at the location stored inside the symlink. It then shows you the contents of the target file or folder....

How to Create Symbolic Link in Linux (ln Command)

You can use the ln command to create links (shortcuts) to files and folders in Linux. The sections below explain how to do it with some examples....

Create Symlink for Directory

A link can also point to a folder’s location (path). Use this command to create a link to a folder in Linux....

Overwrite Symbolic Links

Sometimes, when you try to create a new link file, you might see this error message....

Find Broken Symbolic Links

Sometimes, a link file may stop working if the original file or folder it points to gets moved, deleted, or becomes unavailable (like if a server goes offline). However, the system does not automatically remove these broken link files....

Remove Symbolic Links

If a link file is broken or you don’t need it anymore, you can delete it using the unlink command....

Conclusion

Symbolic links, or symlinks, are like shortcuts that point to files or folders on your Linux system. They allow you to access the target file or folder from a different location. To create a symlink, use the ln -s command followed by the path of the target file/folder, and then the name you want to give the symlink. If a symlink is broken (pointing to a non-existent target), you can find such broken links using the find command with specific options. To remove a symlink you no longer need, simply use the unlink or rm command followed by the name of the symlink file. Remember, symlinks are useful for organizing your files and folders, and for making frequently accessed items more easily accessible....