Created
September 4, 2023 08:39
-
-
Save 5310/bcded72dd7f16ef996d846048fe6dfcb to your computer and use it in GitHub Desktop.
Retarget absolute local symlinks for old mountpoint into relative symlinks #script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This is the old absolute mountpoint which no longer exists | |
old=/mnt/Archive | |
# This is the current mountpoint, | |
# which is factored out of the relative paths, | |
# but is needed for the symlinks to be repaired | |
new=/run/media/deck/Hatshepsut/Archive | |
find . -type l | while read f; do # for each deeply nested symlinks | |
oldtarget=$(readlink "$f") # read the old target | |
if [[ "$oldtarget" =~ ^$old ]]; then # only if the old target used the old mountpoint | |
newtarget=$(echo "$oldtarget" | sed "s:$old:$new:g") # generate a new target with the new mountpoint | |
ln -fsr "$newtarget" "$f" # and force a new symlink relatively with the same symlink file | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment