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

There isn't really any direct way to check for such symlinks. Consider that you might have a filesystem that isn't mounted all the time (eg. an external USB drive), which could contain symlinks to another volume on the system.

You could do something with:

for a in `find / -type l`; do echo "$a -> `readlink $a`"; done | grep destfolder

I note that FreeBSD's find does not support the -lname option, which is why I ended up with the above.


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.


find . -type l -printf '%p -> %l\n'

You can audit symlinks with the symlinks program written by Mark Lord -- it will scan an entire filesystem, normalize symlink paths to absolute form and print them to stdout.

Tags:

Linux

Symlink