2

How I can know if file1 is a symbolic link to a file2? I need an if condition.

  • 1
    I've voted to reopen this issue because the linked duplicate only addresses checking if file is a symlink but not checking if it is a symlink of a specific file. – Jesse_b Apr 25 at 18:03
2

You can use the -h test to determine whether a file is a symbolic link, and -ef to check if it links to a given file (note that -ef isn’t specified by POSIX):

if [ -h file1 -a file1 -ef file2 ]; then
    echo file1 is a symbolic link and equivalent to file2
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.