mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / readlink.mdwn
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):
4
5     $ for FILE in *; do
6           if [ -L "${FILE}" ]; then
7               TARGET=$(readlink "${FILE}");
8               rm -f "${FILE}";
9               ln -s "${TARGET/old-dir\//}" "${FILE}";
10           fi;
11       done
12
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.
16
17 You may also find it useful to rename simlinks so that the link
18 filename matches the target filename:
19
20     $ for x in *; do y=$(basename $(readlink -f "${x}")); mv "${x}" "${y}"; done
21
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.
25
26 [[!tag tags/linux]]