I'm migrating a file system and I need to update a few thousand symbolic links that'll break as a result of the migration. My plan was to find all the affected links and build a script that'd process each link. For example:
ln -nsf "$(readlink "./somelink1" | sed "s|oldpath|newpath|") "$(echo "./somelink1" | sed "s|oldpath|newpath|")"
ln -nsf "$(readlink "./somelink2" | sed "s|oldpath|newpath|") "$(echo "./somelink2" | sed "s|oldpath|newpath|")"
I'll need to run the script as root, however, it looks like that'll change the ownership of the all the links to root:root. Is there a way I can update the links and keep the existing UID:GID? I'm sure I can capture the ownership while the links are enumerated and add a command to chown each link, but I'm wondering if there is a better way to retain ownership?
tarfile
to edit the tar, untar. At least with GNU tar, untarring preserves the ownership and timestamp of symlinks. – Gilles 'SO- stop being evil' Jan 07 '22 at 22:16