Analyze Symbolic Links

Proposed on January 8, 2012:

There is a need for a Unix/Linux tool that deconstructs pathnames, especially in relation to symbolic links (symlinks).

Unless I find someone has already done something like this, I plan on writing a program, most likely called “trln” (for “trace links”) which, given a pathname, will report on stdout a pathname to the same ultimate file, but without any symbolic links in the pathname.

Reason: The presence of symbolic links in a pathname, which links might in turn reference additional symbolic links, can make it hard to identify the actual file that is being referenced.  For example, given a file named “/home/dave/development/source/bin/program”, without a utility, the only way to be certain what file is identified is to proceed backward toward root (“/”) and “ls -ld” each name, in succession, to see if any file(s) in the pathname is a symbolic link.  For example:

# ls -ld /home/dave/development/source/bin/program

# ls -ld /home/dave/development/source/bin

# ls -ld /home/dave/development/source

# ls -ld /home/dave/development

# ls -ld /home/dave

# ls -ld /home

But, it’s far worse than even the long and tedious chain of ls invocations above: If at any point we find a symbolic link, we have to follow that link and repeat the same kind of tedious chain of ls invocations for each link we find, which may turn up even more links that need to be followed. We’re done ls-ing only when we reach root. But, even after that, we may need to assemble pathname fragments we’ve uncovered.

As to the output of my proposed “trln” utility, consider, for example what should be the output if “/home/dave/development” is the only symbolic link and points to “/development/users/dave”.  The invocation and output for “trln” would be as follows:

# trln  /home/dave/development/source/bin/program


If a file referenced by a symbolic link doesn’t exist, the program would indicate on stderr exactly where in the pathname the break occurs. I have additional ideas, including an option (-s) to show the deconstruction step by step on stderr, identifying each symbolic link as it is found and recursively deconstructed. As a separate issue, it might be worthwhile to also indicate points in the pathname where filesystem boundaries are crossed. Further, it might be worthwhile to indicate in the step-by-step (-s) deconstruction if any files have more than one hard link (generally a no-no for directories, and worthy of note even for the terminal file in the pathname).

Here is the stderr output I envision for the -s (step-by-step) option:

/home/dave/development/source/bin/program         #original argument



development -> /development/users/dave








/development/users/dave/source/bin/program        # Final answer

Notice the left-most column always exactly matches the original argument given, with indentation every time a symbolic link is encountered.  I believe it is important to have a single line for each step in the deconstruction, because putting multiple steps on a single line quickly gets confusing and even ambiguous in appearance as symbolic links are encountered and identified. The single-line-per-step approach above can easily accommodate symlinks that reference symlinks that reference symlinks, indenting as needed.

If anyone has any suggestions, identification of a similar program that already exists, or indication you’re interested in my program when it’s done, please leave a comment.


David Braun (MultiTask ComputerWorks)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s