Given this example:
mkdir a ln -s a b ln -s b c ln -s c d
If I execute:
ls -l d
It will show:
d -> c
Is there a way for
ls or any other linux command to show
d -> c -> b -> a instead?
It can do the following part with the -e option
note: readlink a by itself returns b
note #2: together with find -l, a utility to list the chains could easily be written in perl, but also has to be smart enough to detect loops
readlink will not output anything if you have a loop. This is better than getting stuck, I suppose.
Here is a recursive function in Bash:
On multiple lines:
It will fail if names contain backticks, single quotes, or "->". It gets stuck in a loop with symlink loops (this could be solved using an associative array in Bash 4). It exports a variable called "chain" without regard to whether it's already in use.
There may be other problems with it.
Fixed a problem with some relative symlinks. Some still don't work, but the version below doesn't require the target of the link to exist.
Added a version that uses readlink: