Solved

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

Posted on 2003-11-30
8
705 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
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

636 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