30 March 2002 #2

Nemo’s other coding question for the day… How does he find the destination of a symbolic link in shell?


#!/bin/bash

# Find the destination of a link in only shell
# $1 is the name of the file to check (including path if required)

ls -l $1 | tr -s ” ” | sed ‘s/^.*[0-9] //’ | sed ‘s/^.*-> //’

Will return the name of the destination, or the name you handed it if the file is not a symlink.