Sometimes I need to know where a filesystem link points. Sometimes I find that a link points to a link, which then points to a link, and so on, until the final destination file or directory is reached.
The command readlink is good for outputting the next link in a chain of links, or to the final destination file/directory, using the -f option. But why doesn't it show us the whole chain?
So I wrote this quick-n-dirty script to output all links in the chain:
I suspect most people won't want or need this. But I'm posting my random scripts in the prospect that people may learn or be encouraged to write their own scripts.
The command readlink is good for outputting the next link in a chain of links, or to the final destination file/directory, using the -f option. But why doesn't it show us the whole chain?
So I wrote this quick-n-dirty script to output all links in the chain:
Bash:
if ! [[ -e $1 ]]; then exit; fi
CUR_LINK=$1
DEST="$(readlink -f $1)"
while [[ $CUR_LINK != $DEST ]]; do
echo "$CUR_LINK"
CUR_LINK="$(readlink $CUR_LINK)"
done
echo "$DEST"
I suspect most people won't want or need this. But I'm posting my random scripts in the prospect that people may learn or be encouraged to write their own scripts.