Tiny shell script to chase symbolic links to true file name
Posted in 1998
Hi all.
I wrote this shell script to ease some aspects of Informix
administration. I am cross posting it because it has general use. Here
it is:
---------------------------- CUT HERE ----------------------------------
#!/bin/ksh
# truename - chase down theain of symbolic links to obtain the true
# name of a file
# Parameters: Name of a file or a list of file names
#
# Author: Jacob Salomon
# jake@garpac.com
# Date: August 12 1998
# Shell function chase1 - Chase 1 file name to its true name
# Parameter: The file name
chase1 ()
{
PFN=$1
# Get link name, if any. If there is no symbolic link, the loop
# below will not need to start.
#
ls -ld $PFN | awk '{print $NF}' | read link_name
until [ "$link_name" = "$PFN" ] # chase it until no further links
do
PFN=$link_name # Reset for next round of loop
ls -ld $PFN | awk '{print $NF}'|read link_name
done
echo $link_name
}
for FN in $*
do
chase1 $FN | read TN # Get any name this file might link to
# echo $FN : $TN
echo $TNdone
---------------------------- CUT HERE ----------------------------------
--
-- Jake (Retrospectively realizes there is no future in hindsight)
+------------------------------------------------------------+
| The expedient performance of a task with excessive concern |
| regarding its duration-to-completion engenders a virtual |
| certainty of diminished benefit therefrom. |
| -- Benjamin Franklin (but he said it in 3 words) |
+------------------------------------------------------------+