Fixing broken links

rikona rikona at sonic.net
Wed Feb 17 05:39:25 UTC 2016


Hello Ralf,

Tuesday, February 16, 2016, 4:47:38 PM, Ralf wrote:

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

> You seemingly disorganised your disk ;).

True in the 'links' sense. :-) But the 'knowledge' sense is better.

>>Is there a GUI tool

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

I did - there are several places showing how to find bad links, and CL
ways to fix it. BUT, the ways I've found so far will take LOTS of
effort with several hundred things to fix!

> 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.

I wouldn't either, and there are NO 'all' lists to change - each is a
*single* link that needs fixing, and they're ALL different - no
wholesale changes. :-(.

> 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.

Agreed. That's exactly what caused me problems in the past - loops
with chains of links. That's what I most want to find.

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

Agreed - I DON'T want it to be automatic, and that's essentially
impossible because the new link location didn't exist when the bad
link was made, AND the file/dir may have been renamed. A human has to
make that new choice/decision.

My 'thought' GUI would be only a 'helper' - ID the broken links, make
it easy to browse for the new link, transfer the text I select to a
line **that I can edit/rename**, then assemble a new link, test it,
and delete the bad link if the new one works.

> 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/.

That's what I have been doing, ONE file/dir at a time, fixing ONE
link, with several hundred to go. Some are easier to fix by just
editing the properties of the bad link - depends on what needs changing
and what I know about the locations. . I'd sure like to find a way to
speed that up. :-)

Thanks for the reply...

-- 

 rikona        





More information about the ubuntu-users mailing list