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?
|
Given this example:
If I execute:
It will show:
Is there a way for |
|||
|
|
man readlink 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.
|
||||
|
|
|
just use
|
||||
|
|
|
Here is a recursive function in Bash:
On multiple lines:
Examples:
It requires 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. Edit: 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:
|
|||||
|