Lets create simple script:
#!/bin/bash
mypath=$1
while [[ "${#mypath}" -gt 1 ]]; do
file "$mypath"
mypath="$(dirname $mypath)"
done
Test:
$ ./linksinfo /usr/src/linux/kernel/../../../../bin/sh
/usr/src/linux/kernel/../../../../bin/sh: symbolic link to `bash'
/usr/src/linux/kernel/../../../../bin: directory
/usr/src/linux/kernel/../../../..: directory
/usr/src/linux/kernel/../../..: directory
/usr/src/linux/kernel/../..: directory
/usr/src/linux/kernel/..: directory
/usr/src/linux/kernel: directory
/usr/src/linux: symbolic link to `linux-3.14.14-gentoo'
/usr/src: directory
/usr: directory
Edit
This does not check/show all path components, but the output in you question doesn't do this either. For example after
/home/nix/.nix-profile -> /nix/var/nix/profiles/default
it is possible that any of /nix
, /nix/var/
, /nix/var/nix
, /nix/var/nix/profiles
or /nix/var/nix/profiles/default
is a link itself. However your output skips this and checks only /nix/var/nix/profiles/default/lib
. Similar thing happens with
/nix/var/nix/profiles/default/lib/libQt5OpenGL.so -> /nix/store/33xkmx1f1040s5nb15x7hx2cqmyw1jyi-qt-5.3.1/lib/libQt5OpenGL.so
Again the output says nothing about /nix/store
and /nix/store/33xkmx1f1040s5nb15x7hx2cqmyw1jyi-qt-5.3.1
. Long story short I suggest to reconsider the problem and think what you really want to achieve. Perhaps simple readlink [-f]
or realpath [-e]
is enough?
linksinfo
a path to a file, but what do you expect it to do then? – slm Oct 01 '14 at 00:33/
,home
,nix
,.nix-profile
,lib
,libQt5OpenGL.so
) and output destinations of all encountered symlinks, including when them does "chain". It should provide answer to the question "How many symbolic links get dereferenced when I access this path". – Vi. Oct 01 '14 at 00:56ls -ld
. Before writing a tool myself I often "lookup" it using StackExchange. – Vi. Oct 01 '14 at 01:12readlink
. – slm Oct 01 '14 at 01:20symlink
as I've discussed it here: http://unix.stackexchange.com/questions/99159/is-there-an-algorithm-to-decide-if-a-symlink-loops/99166#99166 – slm Oct 01 '14 at 02:22