Can one determine whether a file has symbolic or hard links to it?

Is there any way with a shell command or in a perl script to determine if a file has a symbolic or hard link to it? The obvious solutions, using stat and checking the link count don't seem to work - files with links show count of 1, and directories show a count of 2.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Karl Heinz KremerCommented:
The link count should increase with a hard link, but a symbolic link does not change the file it links to.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

I use ls -la at the command prompt. The results should be similar to the following:  permisions owner group size date_created folder/file name -> folder/file name This is a symbolic link. The first folder/file name is the "linked" directory, the second folder/file name is the "original" folder  or the one linked from.  I think if it is a hard link the -> will become ->> but I am not 100% certain of the hard link symobol.
As khkremer states, only hardlinks will increase the link count.
To detect symlinks, you'd have to read the entire filehierarchy and check all symlinks... Which is more or less to unwieldy to be construed as a solution:-). Simple anser: no, not for symbolic links.

-- Glenn
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

GodAuthor Commented:
GodAuthor Commented:
How do you divy up points?
Used to be a "Split Points" link near the comment entrybox... Some have had luck with oldlook ...

-- Glenn
Karl Heinz KremerCommented:
You can probably file a request in the Community Support area if you want to split points.
GodAuthor Commented:
I'm sorry - I meant to credit Khkremer - but I'd like to give a portion to Gns as he clarified some more.  Tagish, I appologize - I did not intend to accept your answer.  I appreciate your comment, but it doesn't deal with link count.  I will post the point correction in community support.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.