Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for symbolic link

I have a symbolic link a.c in my home directory to another file in the same directory.

a.c -> b.c

I know how to check a.c is a symbolic link using the shell script

if [ -L /home/nit/a.c ] ; then
    echo "a.c is a symbolic link"
fi

But my question is how to write a shell script to check whether a.c is a symbolic link specifically to b.c ?

Thanks

like image 311
nitin_cherian Avatar asked Dec 30 '10 08:12

nitin_cherian


2 Answers

Use readlink;

[~]> ln -s foo bar
[~]> readlink bar 
foo
like image 193
ismail Avatar answered Oct 13 '22 19:10

ismail


You could also do ls -F filename.txt which returns filename.txt@ if it is a symbolic link.

like image 23
mohit6up Avatar answered Oct 13 '22 19:10

mohit6up