Fixing broken links

Ralf Mardorf silver.bullet at zoho.com
Wed Feb 17 00:47:38 UTC 2016


On Tue, 16 Feb 2016 14:16:35 -0800, rikona wrote:
>I reorganize my disks and that breaks links.

You seemingly disorganised your disk ;).

>Is there a GUI tool

I don't know. You likely found hints how to use command line.

http://unix.stackexchange.com/questions/34248/how-can-i-find-broken-symlinks

[rocketmouse at archlinux Desktop]$ ls -Gg *
-rw-r--r-- 1    0 Feb 17 00:28 a
-rw-r--r-- 1    0 Feb 17 00:28 b
lrwxrwxrwx 1    1 Feb 17 00:29 c -> b
lrwxrwxrwx 1    1 Feb 17 00:29 d -> e
lrwxrwxrwx 1    1 Feb 17 00:30 f -> g
lrwxrwxrwx 1    1 Feb 17 00:30 g -> f
lrwxrwxrwx 1   15 Feb 17 01:27 me_myself_and_i -> me_myself_and_i
lrwxrwxrwx 1   11 Feb 17 00:50 z -> directory_1

directory:
total 0
-rw-r--r-- 1 0 Feb 17 00:33 a
-rw-r--r-- 1 0 Feb 17 00:33 b
lrwxrwxrwx 1 1 Feb 17 00:34 c -> b
lrwxrwxrwx 1 1 Feb 17 00:34 d -> e
lrwxrwxrwx 1 1 Feb 17 00:34 f -> g
lrwxrwxrwx 1 1 Feb 17 00:34 g -> f

directory_2:
total 0
[rocketmouse at archlinux Desktop]$ echo; for l in $(find . -type l); do cd $(dirname $l); if [ ! -e "$(readlink $(basename $l))" ]; then echo -n "$l -> "; fi; cd - > /dev/null; if [ ! -e "$(readlink $(basename $l))" ]; then readlink $l; fi; done

./f -> g
./z -> directory_1
./directory/f -> g
./directory/d -> e
./directory/g -> f
./d -> e
./me_myself_and_i -> me_myself_and_i
./g -> f

So you get a list of all broken links, but it's also possible to
e.g. find all links against "directory_1" and to change those links to
link against e.g. "directory_2" instead of linking against
"directory_1", but I wouldn't do this. You also could sort and compare
to find circular links, but while this might be easy to solve for
"1 -> 2" vs "2 -> 1" and easier for "me_myself_and_i -> me_myself_and_i",
it becomes tricky when the loops are caused by a chain of links.

I would be careful with using a script or a GUI tool that automatically
reorganizes links.

Assumed you used links against /mnt/old/foo and now there
isn't /mnt/old/ anymore, now the links should be against /mnt/new/foo,
then I wouldn't change all links, I would create a link
/mnt/old -> /mnt/new/.





More information about the ubuntu-users mailing list