1 I moved a directory containing a bunch of symbolic links today, and
2 the links all broke. I fixed the links with the following Bash
3 oneliner (split across lines in this post for clarity):
6 if [ -L "${FILE}" ]; then
7 TARGET=$(readlink "${FILE}");
9 ln -s "${TARGET/old-dir\//}" "${FILE}";
13 `readlink` prints the value of a symbolic link and
14 `${TARGET/old-dir\//}` creates the new link target by removing
15 `old-dir/` from the original target.
17 You may also find it useful to rename simlinks so that the link
18 filename matches the target filename:
20 $ for x in *; do y=$(basename $(readlink -f "${x}")); mv "${x}" "${y}"; done
22 This assumes that everything globbed into `x` is a link. If not, you
23 can add an `if [ -L "${x}" ]` block like I did in my
24 target-translation example.