Nesse caso, essa é uma "alternativa" do Debian, portanto, para obter mais detalhes, você pode usar:
$ update-alternatives --display gnome-text-editor
gnome-text-editor - auto mode
link best version is /usr/bin/gedit
link currently points to /usr/bin/gedit
link gnome-text-editor is /usr/bin/gnome-text-editor
slave gnome-text-editor.1.gz is /usr/share/man/man1/gnome-text-editor.1.gz
/usr/bin/gedit - priority 50
slave gnome-text-editor.1.gz: /usr/share/man/man1/gedit.1.gz
/usr/bin/leafpad - priority 40
slave gnome-text-editor.1.gz: /usr/share/man/man1/leafpad.1.gz
Mais geralmente, no Linux, você pode usar o comando namei
para saber sobre todos os links simbólicos envolvidos na resolução de um caminho (também pontos de montagem com -x
):
$ namei -lx /usr/bin/gnome-text-editor
f: /usr/bin/gnome-text-editor
Drwxr-xr-x root root /
drwxr-xr-x root root usr
drwxr-xr-x root root bin
lrwxrwxrwx root root gnome-text-editor -> /etc/alternatives/gnome-text-editor
Drwxr-xr-x root root /
drwxr-xr-x root root etc
drwxr-xr-x root root alternatives
lrwxrwxrwx root root gnome-text-editor -> /usr/bin/gedit
Drwxr-xr-x root root /
drwxr-xr-x root root usr
drwxr-xr-x root root bin
-rwxr-xr-x root root gedit
Para uma resposta mais direta à sua pergunta, eu faria algo como:
#! /bin/zsh -
zmodload zsh/stat || exit
ret=0
for file do
n=0
while
ls -ld -- "$file" || ! ret=1 && [ -L "$file" ]
do
if ((++n > 40)) && [ ! -e "$file" ]; then
echo >&2 too many symlinks
ret=1
break
fi
zstat -A target +link -- "$file" || ! ret=1 || break
case $target in
(/*) file=$target;;
(*) file=$file:h/$target
esac
done
done
exit "$ret"
Isso pode não fornecer todas as informações necessárias para entender o que está acontecendo. Compare por exemplo:
$ ./resolve-symlink b/b/b/b/x/b
lrwxrwxrwx 1 stephane stephane 1 Mar 18 15:37 b/b/b/b/x/b -> a
lrwxrwxrwx 1 stephane stephane 4 Mar 18 15:37 b/b/b/b/x/a -> ../a
lrwxrwxrwx 1 stephane stephane 26 Mar 18 15:15 b/b/b/b/x/../a -> /usr/bin/gnome-text-editor
lrwxrwxrwx 1 root root 35 Nov 5 2013 /usr/bin/gnome-text-editor -> /etc/alternatives/gnome-text-editor
lrwxrwxrwx 1 root root 14 Mar 15 12:21 /etc/alternatives/gnome-text-editor -> /usr/bin/gedit
-rwxr-xr-x 1 root root 10344 Nov 12 17:18 /usr/bin/gedit
Com:
$ namei -lx b/b/b/b/x/b
f: b/b/b/b/x/b
lrwxrwxrwx stephane stephane b -> .
drwxr-xr-x stephane stephane .
lrwxrwxrwx stephane stephane b -> .
drwxr-xr-x stephane stephane .
lrwxrwxrwx stephane stephane b -> .
drwxr-xr-x stephane stephane .
lrwxrwxrwx stephane stephane b -> .
drwxr-xr-x stephane stephane .
lrwxrwxrwx stephane stephane x -> 2
drwxr-xr-x stephane stephane 2
lrwxrwxrwx stephane stephane b -> a
lrwxrwxrwx stephane stephane a -> ../a
drwxr-xr-x stephane stephane ..
lrwxrwxrwx stephane stephane a -> /usr/bin/gnome-text-editor
Drwxr-xr-x root root /
drwxr-xr-x root root usr
drwxr-xr-x root root bin
lrwxrwxrwx root root gnome-text-editor -> /etc/alternatives/gnome-text-editor
Drwxr-xr-x root root /
drwxr-xr-x root root etc
drwxr-xr-x root root alternatives
lrwxrwxrwx root root gnome-text-editor -> /usr/bin/gedit
Drwxr-xr-x root root /
drwxr-xr-x root root usr
drwxr-xr-x root root bin
-rwxr-xr-x root root gedit