I have a web app that has a bunch of symbolic links in subdirectories throughout it. I need to move the app to another directory structure, and I need to update all the symlinks to point to the new path. For example:
Old Dir: /home/user/public_html/dev
New Dir: /home/user/public_html/qa
Old Symlink: /home/user/public_html/qa/multisites/slave01/images -> /home/user/public_html/dev/images
New Symlink: /home/user/public_html/qa/multisites/slave01/images -> /home/user/public_html/qa/images
The problem is that there's a lot of these scattered throughout various directories. How can I recursively search from the root and recreate all symlinks pointing to /dev/
with /qa/
?
Best Answer
This bash command should do it for you:
It uses
find
to identify all files in theqa
directory that are symbolic links with a target that's in thedev
directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path inqa/
. After you run this, just execute the generated script withYou might want to examine it manually first to make sure it worked.
Here's a more verbose version of the above
find
command for easier reading (though I wouldn't necessarily write it this way in practice):