Home > Blockchain >  Is there a way to see outbound symbolic links?
Is there a way to see outbound symbolic links?

Time:10-29

I know how to see and inbound symbolic links as follows:

I can simply use ls -al and will see entries like

lrwxr-xr-x 1 c staff 32 Oct 28 11:14 .zshrc -> /Users/c/top/ll/config/zshell.sh

where the link flag is set and I can see the connected real file.

But if I look at the real file in the same manner I can not see that is used to create a symbolic link:

-rw-r--r-- 1 c staff 2152 Oct 27 17:52 zshell.sh

CodePudding user response:

A symbolic link is best viewed not like a relationship with two ends, but like a text file containing a file path, which is automatically read by file system commands. As such, the file system never knows which paths are currently the target of a symbolic link. Indeed, the target might be non-existent, or on a different file system.

The best you can do is search the file system (or a particular subset where you think a link might be) for any symbolic links matching a particular path. The Swiss Army Knife that is the Unix "find" command offers an option for this:

-lname pattern

File is a symbolic link whose contents match shell pattern pattern. The metacharacters do not treat '/' or '.' specially. If the -L option or the -follow option is in effect, this test returns false unless the symbolic link is broken.

So in your example, you could run this to hunt through your entire mounted file system for links to the given file:

find / -lname /Users/c/top/ll/config/zshell.sh

Beware however that symlinks can also be relative, so the target may depend both on the contents and the location of the symlink. For instance, a link in /Users/c/top/ could have a target of "./ll/config/zshell.sh", and would not be found by that pattern. You could broaden the pattern to "*/zshell.sh", but would then have to check the results for which ones actually resolved to your desired target.

CodePudding user response:

No, there's no tracking like that. Symbolic links are essentially just small text files that are treated specially; in fact, they don't always even refer to real files that exist.

  • Related