Fixing broken links

Luis Paulo luis.barbas at gmail.com
Wed Feb 17 22:32:30 UTC 2016


On Wed, Feb 17, 2016 at 7:30 AM, rikona <rikona at sonic.net> wrote:

> 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
> >>
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>

Hi, rikona

1. In a terminal go to your user home and run:
 $ sudo find -L . -type l -exec ls -l '{}' \; > ~/broken.txt 2> ~/loops.txt

In the end, broken links listed on broken.txt and file system loops on
loops.txt, both text files on your home directory.

If you don't have spaces on your file names, it would be easy to rename
broken.txt to broken.csv and load it on a spreadsheet. Not that I believe
it would be of much help, and that's point 2.

2. About your link problem, can you live without those links? If so, why
not just delete all broken links if you have a list? I mean, what is not
working?

Other suggestions given here are all good, I think, but if you don't know
what you have changed, from where to where, don't have a good idea how to
go back (maybe you do, I don't know), and worse, if in between you have
corrected some links but not others, it will be a huge job repairing a few
hundred broken links.

Without knowing more, I'll say, please allow me to be direct, that I don't
see why should anyone have hundreds of links in their home dir. Again
without knowing more,I'll say your goal should be to remove all links,
broken or not (and by that read all or almost all).

If you can't live without them, the broken links, than you have what was
said and you said, redo the original dir structure, or group them some how
and figure a way, ... I'm pretty sure no tool will do it automatically.

Please understand I'm trying to be helpful, not to be radical and just say
stuff. Repairing those links its probable to be a major headache if you
don't know (or have a pretty good idea on) how to go back to the original
structure.

So for now my advice is: if you can live with the broken links, then erase
them all, and try to create new ones as less as possible, and only if they
are really useful/necessary for some effect.

Best regards, Luis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20160217/a8ba18ec/attachment.html>


More information about the ubuntu-users mailing list