Changing absolute to relative symbolic links?

I look for a way to change absolute symbolic links to relative ones. Searching revealed the tool symlinks, which could do what I want, but I cannot find it in the Suse repositories.
What tool do Suse users use for the maintenance of existing symbolic links?**

I am using EXT4, Suse 11.2. The install/boot sub-forum appeared the most appropriate to me, due to its tag “filesystems”. I apologise if this does not fit here.

Detailed example:
I automatically created the following symbolic links in my picture album directory, which is simply a selection of nicer photos stored in elsewhere:

/home/sturtle/Privat/Bilder/Alben/2010> ll
pic27.jpg -> /home/turtle/Privat/Bilder/Urlaub/Schottland/pic27.jpg
pic76.jpg -> /home/turtle/Privat/Bilder/Urlaub/Deutschland/pic76.jpg

Since I share the family photos with others, /home/turtle/Privat/Bilder is itself a symbolic link to /home/multimedia/Bilder. So in reality the pictures exist at these absolute paths:


The problem now is that others cannot use these album collections, since the absolute symbolic links into my home directory do not work for them. Even worse, I do not even have a home directory at some of the machines where a mirror copy of /multimedia exists.

So I would rather have the following relative symbolic links, which would work everywhere:

/home/multimedia/Bilder/Alben/2010> ll
pic27.jpg -> ../../Urlaub/Schottland/pic27.jpg
pic76.jpg -> ../../Urlaub/Deutschland/pic76.jpg

Now we are talking about a few hundred symbolic links in total to be changed, so an automatic tool would be necessary.

BTW, my pictures are organised with Kphotoalbum, and I create the symlinks by drag-and-drop from Kphotoalbum to Dolphin. Yes, this is a workaround, since I believe that Kphotoalbum cannot export its database to IPTC-tags nor Digikam (which could then export to IPTC) at the moment. So a tool which could turn part of the path of a symbolic link into IPTC keywords would also resolve the problem, but I guess dealing with symbolic links is easier or more common.

I don’t know of any tools offhand, but if I were faced with this problem I would probably use Perl to solve it. It really is just a string processing problem to remove the common ancestor in the two paths and change what remains to a relative path.

It’s not too hard if you only need to convert one level of link, but if there are symlinks in the directories on the path, then it is tricker. Fortunately if there is only one, that could be factored out ahead of time and “hardwired” into the string substitution.

Look at /usr/lib/rpm/brp-symlink as idea.
This script makes what you want when rpm builds packages.

Thanks for the suggestions. I have no knowledge about either Perl nor Scripts, so I doubt this will be an easy task for me. :confused:

I did get ahead somewhat, since I remembered that there are other package searches beyond what Suse provides, so I found a symlinks package on RPM search.

Alas, its shortening function does not work, whatever I do, and in whatever directory I move the links, I always end up with:

/home/sturtle/Privat/Bilder/Alben/2010> ll
pic27.jpg -> ../../../../home/sturtle/Privat/Bilder/Urlaub/Schottland/pic27.jpg
pic76.jpg -> ../../../../home/sturtle/Privat/Bilder/Urlaub/Deutschland/pic76.jpg

which does not really help.

symlinks does recognise them as “lengthy” but option -cs does not fix this as the manpage would promise.

Just do it twice;):

symlinks -cs foodir; symlinks -cs foodir

(or “-crs” if you want to do it recursivley). The first instance it just convert absolute to relative (with the result you have shown), while the second one shortens the lengthy paths.

Good luck!

Ouch! So simple, it hurts. :’(

Nevertheless, this still does help me a lot - even though 2 years have passed since I asked initially, I had not found a good solution yet, just clumsy workarounds. Now this is much better, and eventually allows me to make my Kphotoalbum album selection browsable on my TV.
Thanks a lot for replying! :slight_smile: