I just added follow-symlinks to my colas-bash-lib collection. It is a small bash script that traces and expands all the symlinks of a file, recursively, and shows you the mount points and the dangling links found along the way.
I made it because there are no existing linux utilities that show both the mount points and the symbolic link traversed to get to the file.
What it shows🔗
Give it the path of a file or directory and it walks the chain, printing each hop:
## /tmp/symtest/chain
Mount: /tmp
'/tmp/symtest/chain' -> 'link-to-real'
=> /tmp/symtest/link-to-realThe output is made for human consumption:
->the file is a symbolic link to=>the final target=the path after normalization (resolving/..,/./,//)Mount:a filesystem boundary — printed when the mount point changes*** File not found:a dangling link
It also resolves the relative links and the .. segments for you, so what you read is what the kernel will actually open, not the spelling on disk.
The dangling links🔗
Dangling (or broken) links get a useful diagnostic to know the missing link.
## /tmp/symtest/dangling
Mount: /tmp
'/tmp/symtest/dangling' -> 'missing-file'
*** File not found: /tmp/symtest/missing-file
Because in missing directory: /tmp/symtest/missing-fileThe mount points🔗
Links that cross a mount point are easy to miss — the file is the same name, but it lives on another filesystem, with its own space and speed characteristics:
## /tmp/symtest/link-to-etc
Mount: /tmp
'/tmp/symtest/link-to-etc' -> '/etc'
Mount: /
=> /etcWhy I like it🔗
- One shot, whole chain: it prints everything in one pass instead of me chaining
ls -landreadlinkby hand. - A reason, not a symptom: for broken links it tells me the missing directory, not just "file not found".
- Pure bash, no dependencies — it only uses
readlink,statandrealpath, all of which are everywhere.
See it and the rest of my bash scripts at colas-bash-lib.