Fixing broken links

rikona rikona at sonic.net
Wed Feb 17 07:30:23 UTC 2016


Hello Luis,

Tuesday, February 16, 2016, 10:19:32 PM, Luis wrote:

> I was doing some tests to list broken links and file system loops (I know
> that you already have, bare with me):
>  $ sudo find -L . -type l -exec ls -l '{}' \; > ~/broken.txt

> Then I run it on my root and, surprise, I had a few hundred bad links too.
> When I cancel the command I had already a 33Mb text file.

> As I notice /proc on the screen, I removed that directory from the results.
> Then I removed /sys, /run and /var/run.

> Then I removed from the results a /usr/share/help and some obvious old and
> temp backups dirs in my home, and I ended up just with a few bad links.

> So I'm just asking if your situation may be kind of similar, or it is in
> fact the enormity of (real) bad links. That's some hope, isn't it?

Unfortunately, no. :-( I started from the user home dir so didn't get
any of the sys links - they're all bad real links that I made, no sys
links.

> Also the above command plus ' 2> ~/loops.txt' at the end will list file
> system loops at ~/loops,txt,

How does this give loops? I don't understand...

Thanks for the info and potential help.

-- 

 rikona

> On Wed, Feb 17, 2016 at 12:47 AM, Ralf Mardorf <silver.bullet at zoho.com>
> 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 ;).
>>
>> >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/.
>>
>>
>> --
>> ubuntu-users mailing list
>> ubuntu-users at lists.ubuntu.com
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>>







More information about the ubuntu-users mailing list