Skip to content
Advertisement

Is there a way to check if there are symbolic links pointing to a directory?

I have a folder on my server to which I had a number of symbolic links pointing. I’ve since created a new folder and I want to change all those symbolic links to point to the new folder. I’d considered replacing the original folder with a symlink to the new folder, but it seems that if I continued with that practice it could get very messy very fast.

What I’ve been doing is manually changing the symlinks to point to the new folder, but I may have missed a couple.

Is there a way to check if there are any symlinks pointing to a particular folder?

Advertisement

Answer

I’d use the find command.

find . -lname /particular/folder

That will recursively search the current directory for symlinks to /particular/folder. Note that it will only find absolute symlinks. A similar command can be used to search for all symlinks pointing at objects called “folder”:

find . -lname '*folder'

From there you would need to weed out any false positives.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement