重命名之类的东西适用于文件,但适用于符号链接目标。
所以如果我有
link1 -> /usr/share/lib-1.2.2/file1
link2 -> /usr/share/lib-1.2.2/file2
我可以做
rename 1.2.2 2.0.3 link*
并且有
link1 -> /usr/share/lib-2.0.3/file1
link2 -> /usr/share/lib-2.0.3/file2
使用这个脚本:
#!/bin/sh
from="$1"
to="$2"
shift 2
for i
do
a=$(readlink "$i") && ln -sf "$(echo $a | sed "s@$from@$to@")" "$i"
done
使用示例:
$ ls -l
total 0
lrwxrwxrwx 1 igor igor 6 Jul 12 18:56 1 -> /bin/1
lrwxrwxrwx 1 igor igor 7 Jul 12 18:56 10 -> /bin/10
lrwxrwxrwx 1 igor igor 6 Jul 12 18:56 2 -> /bin/2
lrwxrwxrwx 1 igor igor 6 Jul 12 18:56 3 -> /bin/3
lrwxrwxrwx 1 igor igor 6 Jul 12 18:56 4 -> /bin/4
lrwxrwxrwx 1 igor igor 6 Jul 12 18:56 5 -> /bin/5
lrwxrwxrwx 1 igor igor 6 Jul 12 18:56 6 -> /bin/6
lrwxrwxrwx 1 igor igor 6 Jul 12 18:56 7 -> /bin/7
lrwxrwxrwx 1 igor igor 6 Jul 12 18:56 8 -> /bin/8
lrwxrwxrwx 1 igor igor 6 Jul 12 18:56 9 -> /bin/9
<links>$ bash ../rename-links /bin/ /usr/bin/ *
<links>$ ls -l
total 0
lrwxrwxrwx 1 igor igor 10 Jul 12 18:57 1 -> /usr/bin/1
lrwxrwxrwx 1 igor igor 11 Jul 12 18:57 10 -> /usr/bin/10
lrwxrwxrwx 1 igor igor 10 Jul 12 18:57 2 -> /usr/bin/2
lrwxrwxrwx 1 igor igor 10 Jul 12 18:57 3 -> /usr/bin/3
lrwxrwxrwx 1 igor igor 10 Jul 12 18:57 4 -> /usr/bin/4
lrwxrwxrwx 1 igor igor 10 Jul 12 18:57 5 -> /usr/bin/5
lrwxrwxrwx 1 igor igor 10 Jul 12 18:57 6 -> /usr/bin/6
lrwxrwxrwx 1 igor igor 10 Jul 12 18:57 7 -> /usr/bin/7
lrwxrwxrwx 1 igor igor 10 Jul 12 18:57 8 -> /usr/bin/8
lrwxrwxrwx 1 igor igor 10 Jul 12 18:57 9 -> /usr/bin/9
重命名(1): - 支持新的命令行选项 --symlink 重命名符号链接目标