I came up with this chain:
find . -type l -ls | egrep -o -- '-> .+$' | sort | uniq -c
It lists all symbolic links, greps for whatever comes after ->
, sorts it and groups it.
It is a first step, but by far not perfect. You can run find
on /
to get a big list, but if the symbolic link is to a relative target, the command will group them together even if they are not the same.
Example:
/home/shi/bin/list.sh -> ./show.sh
/home/shi/sbin/all.sh -> ./show.sh
show.sh
might be different programs - one in bin
and another one in sbin
.
Another issue are regular file names with ->
in them (not very common, though). The format of ls
cannot distinguish this.
Example:
test.sh -> all.sh -> list.sh
A file called test.sh
might link to all.sh -> list.sh
or a file called test.sh -> all.sh
might link to list.sh
.
I hope this helps in your case. For a perfect solution you should use a script (sh, PHP, Perl).