I want to do some housekeeping in a directory, and I want to see if a given directory has any symlinks pointing to it. I can easily enough see what directory a symlink points to, but now I want to see the relationship in reverse.
|
|
Symbolic links are not tracked, so you'll have to perform an exhaustive search. Furthermore, symbolic links are textual, so they keep “existing” even if the filesystem they reside on is unmounted (and they may have a different target if mounted in a different place or if you rename directories). So the most you can do is find the symbolic links pointing to a particular file (or directory), say (Note that I assume you are really looking for symbolic links to a particular directory. Finding symbolic links pointing into a directory (i.e. to a file or subdirectory of that directory) or accross a directory (i.e. that may become dangling if you remove the directory) are much harder problems.) With some versions of find (e.g. on (recent enough) Linux, FreeBSD or Mac OS X), you can easily look for symbolic links whose target is
On systems whose
Doing this with only POSIX tools is a lot harder, due to the lack of POSIX ways to test same-file-ness or obtain information about symbolic links. Here's a solution for directories; it assumes there are no newlines in any filename. With some shells, you may need to replace
And here's my obligatory zsh solution.
|
|||||
|
|
You'll need to search from |
|||
|
