Two Linux paths can contain identical bytes for different reasons. One may be an independent copy, or both names may be hard links to the same file. A checksum cannot tell you which explanation is true. For existing paths on the same system, compare device and inode together, and decide whether you mean the symlink itself or its target.
Build four paths in a disposable directory
Use Bash, GNU Coreutils, and a writable Linux directory on a filesystem that supports hard links and symbolic links. Save this as links.sh. It creates all four paths next to each other and removes the fixture directory on exit. Nothing outside that directory is used as file data.
#!/usr/bin/env bash
set -eu
scratch=$(mktemp -d ./links-demo.XXXXXX)
trap 'rm -rf -- "$scratch"' EXIT
(
cd "$scratch"
printf 'sample\n' > original
ln -- original alias
cp -- original copy
ln -s -- original shortcut
identity() { stat --format='%d:%i' -- "$1"; }
target=$(identity original)
test "$target" = "$(identity alias)"
test "$target" != "$(identity copy)"
test "$target" != "$(identity shortcut)"
test "$target" = "$(stat -L --format='%d:%i' -- shortcut)"
count=$(stat --format='%h' -- original)
test "$count" = 2
printf 'shared inode: original and alias; links=%s\n' "$count"
)Run bash links.sh. Expected output:
shared inode: original and alias; links=2Compare identity before interpreting the link count
GNU stat supplies the filesystem device number with %d, the inode number with %i, and the hard-link count with %h. Inode numbers can repeat across filesystems, so comparing just %i can incorrectly combine unrelated files. The alias shares the source's pair. The copy gets a different pair even though its bytes match. Without -L the symbolic link is inspected as its own entry. With -L the same name resolves to the original. Merely adding a symlink does not increment the original's hard-link count.
Troubleshoot a failed check
If ln fails, check filesystem support and whether the source and destination are on the same filesystem. If stat rejects --format, make sure you are running GNU rather than a BSD implementation. A dangling symlink can be inspected without dereferencing, but there is no target identity to report with -L. For a changing directory, treat the result as an observation at scan time. Files may be replaced between checks, and inode numbers can be reused. Do not use an old pair as a persistent file identifier or as proof that a later destructive operation is safe.
Primary reference and related tutorials: GNU Coreutils stat invocation · Java Samples Linux tutorials.