Solved

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

Posted on 2003-11-30
8
698 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
  • 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
 

Author Comment

by:God
ID: 9850566
darn.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now