Solved

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

Posted on 2003-11-30
8
704 Views
Last Modified: 2006-11-17
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.
0
Comment
Question by:God
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 100 total points
ID: 9846946
The link count should increase with a hard link, but a symbolic link does not change the file it links to.
0
 

Expert Comment

by:tagish
ID: 9848627
Hello,

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.
 
0
 
LVL 20

Assisted Solution

by:Gns
Gns earned 25 total points
ID: 9849638
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
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:God
ID: 9850566
darn.
0
 

Author Comment

by:God
ID: 9850571
How do you divy up points?
0
 
LVL 20

Expert Comment

by:Gns
ID: 9850803
Used to be a "Split Points" link near the comment entrybox... Some have had luck with oldlook ... http://oldlook.experts-exchange.com/Operating_Systems/Linux/Q_20812105.html#9850566

-- Glenn
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9851240
You can probably file a request in the Community Support area if you want to split points.
0
 

Author Comment

by:God
ID: 9851848
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.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question