Skip to content

Instantly share code, notes, and snippets.

@stephan281094
Last active February 8, 2017 09:17
Show Gist options
  • Save stephan281094/8b82d00f2d0cb7169f05dad74e714ddd to your computer and use it in GitHub Desktop.
Save stephan281094/8b82d00f2d0cb7169f05dad74e714ddd to your computer and use it in GitHub Desktop.
Make it easy to bulk replace symlink targets with a common pattern.
#!/bin/bash
for sym in $(find $1 -type l); do
target=$(readlink $sym)
new=${target/$2/$3}
echo "Retargeting '$sym' to '$new'.."
rm $sym && ln -s $new $sym
done
@stephan281094
Copy link
Author

stephan281094 commented Feb 7, 2017

Retarget symlinks

Make it easy to bulk replace symlink targets with a common pattern.

Usage

$ ./retargetsym.sh 'path/**/links/*' '/old/path' '/new/path'

How it works

  1. It looks for symlinks matching the passed pattern.
  2. It determines the target of each symlink.
  3. It determines the new target by looking for a string and replacing it with another one.
  4. It deletes the symlink and creates a new one with the new target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment