Greetings!!

I have run accross this issue in the past and solved it by writing Bourne, Korn and BASH shell scripts to find all paths to a single inode.

In Unix/Linux operating systems, a hard link is basically another path pointing to the same inode. Unfortunately, there's no quick and easy solution for finding all the places (paths) that point to that same inode. Here's the basics of how I've done this in the past.

  1. Use ls -i filename to find the inode of the file in question.
  2. Use find / -inum XXXXXX -print to find the full path for each file pointing to inode XXXXXX.

Note that this is searching from the root, and can take quite a while. Not necessarily the most desirable of solutions, but it's worked in the past.

One of our applications makes very heavy use of hard links. Often our clients do not understand hard linking and might move things around or inadvertently break links. I've taken this very shell script idea and used it to help me reconcile the links and report on those that are misplaced, broken or completely missing.

Are you looking for a perl solution to your problem? If so, I've not yet developed something to trace down inodes. I would certainly like to give it a try, however. If you are looking for a basic shell utility, it's not hard to write one up.

I note that you mention the utility you saw previously did not use ls -i filename. However, many utilities on Unix systems are collections of the basic shell functions of the system, like ls and find. You might find that down in the workings of this utility, it is making use of good old Unix standard utilites.

Alternatively, it could be that this utility, if written in something like C, made use of the underlying C functions behind ls and find.

With a perl solution, it might be hard to get away from the heavy IO you are experiencing in File::Find. I do think it is worth a shot.

-Daruma

In reply to Re: locate path to a file from inode number by Daruma
in thread locate path to a file from inode number by gnu@perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.