nitin_cherian
nitin_cherian

Reputation: 6655

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

Upvotes: 17

Views: 35214

Answers (2)

mohit6up
mohit6up

Reputation: 4348

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

Upvotes: 6

ismail
ismail

Reputation: 47602

Use readlink;

[~]> ln -s foo bar
[~]> readlink bar 
foo

Upvotes: 28

Related Questions