What are the best tools/programming-techniques for following a complicated nesting of symlinks and completely capturing and reporting on every symlink along the way, including those in the middle of a path (See below for more info).
Here’s a specific example. Consider the following output from a shell command
ls -l /Library/Java/Home lrwxr-xr-x 1 root admin 48 Feb 24 12:58 /Library/Java/Home -> /System/Library/Frameworks/JavaVM.framework/Home
The ls command lets you know that the file /Library/Java/Home file is a symlink to another location. However, it doesn’t let you know that the thing it’s pointing to is also a symlink
ls -l /System/Library/Frameworks/JavaVM.framework/Home lrwxr-xr-x 1 root wheel 24 Feb 24 12:58 /System/Library/Frameworks/JavaVM.framework/Home -> Versions/CurrentJDK/Home
This, in turn, doesn’t let you know that part of the path of the pointed to file is a symlink.
ls -l /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK lrwxr-xr-x 1 root wheel 3 Feb 24 12:58 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK -> 1.5
Which, just to complete this tale, is another symlink
ls -l /System/Library/Frameworks/JavaVM.framework/Versions/1.5 lrwxr-xr-x 1 root wheel 5 Feb 24 12:58 /System/Library/Frameworks/JavaVM.framework/Versions/1.5 -> 1.5.0
Finally pointing at a ‘real’ folder.
Are there any tools that can visualize the full chain of links for you in some way (either graphically or plain old text)? I’m sure one could script this themselves (and if you want to, please do it and share!), but it seems like the kind of thing that would be fraught with ‘oh, crap, edge case. Oh, crap, ANOTHER edge case’. I’m hoping someone’s already gone to the bother.
I do freelance/contract work, and everyone uses symlinks slightly differently to install their PHP applications on a web-server. Half my job is usually un-nesting this (inevitably) undocumented hierarchy so we know where to put our new code/modules.
Tcl has a command [file type $filename] that will return ‘link’ if it’s a link. It has another command [file link $filename] that will return what the link points to. With those two commands it’s possible to take a link and follow the links until you get to an actual file.
Perhaps something like this off the top of my head:
You’ll get output that looks like:
If there’s a circular link it will look like: