Solved

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

Posted on 2003-11-30
8
703 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ftp to port 21 4 66
VMware Tools Install On Linux Problem 3 101
Internal CA server 6 88
Migrating a Linux server to VMware 3 103
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

679 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