I have morass of chained symlinks like this scattered around:
A (symlink) -> B (symlink) -> C (file)
Some may even involve longer chains, I'm not sure yet.
When manually examining a single file it's easy to see what's going on but I'm looking for an automated way to find these and (preferably) clean them up.
In the example above I would want the B->C symlink to stay in place but the A->B symlink would become A->C
Identifying them if the main goal; the quantity might end up being sufficiently low that fixing them manually wouldn't be a big deal. But finding them all manually isn't feasible.
I'm aware of the "symlinks" utility and it is useful in many scenarios such as finding dangling symlinks, but it doesn't seem to have the ability to detect "chains" like this
I'm aware of "find -type l" as well as the -L option for find but they don't seem to work together as "find -L -type l" always returns an empty response.
I make use of "find -type l -exec ls -l {} +" (which works better than find's -ls option) and tried to use it to obtain a list of symlink destinations which I could then check to see if they're symlinks or not, however, all the symlinks are relative rather than absolute so the output is a bit messy
for example I get outputs like this:
lrwxrwxrwx 1 username 50 Nov 5 01:00 ./a/b/c/d -> ../../e/f/g/h
From that I have to think a bit to figure out that the actual symlink destination is ./a/e/f/g/h (and I can then check to see if it's a symlink or not), not really ideal for automation
If the symlinks were (temporarily) absolute rather than relative this would be easier but the "symlinks" utility can only convert absolute -> relative; as far as I can tell it can't convert relative -> absolute.