Created
April 17, 2025 17:29
-
-
Save jimdiroffii/3b8dc72df14f53cfe11a61004f0d0953 to your computer and use it in GitHub Desktop.
Find all symlinks and change their link path
This file contains hidden or 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 | |
# update `/search/path/dir`, `/old/link/path`, and `/new/link/path` | |
find /search/path/dir -type l | while read link; do | |
target=$(readlink "$link") | |
if [[ "$target" == "/old/link/path"* ]]; then | |
suffix="${target#/old/link/path}" | |
newtarget="/new/link/path$suffix" | |
echo "Updating: $link -> $newtarget" | |
# Comment these two lines out for a dry run with no changes | |
rm "$link" | |
ln -s "$newtarget" "$link" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run
find
first to just list the links that might need to be updated: