Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Finding Hard links

by powerman (Friar)
on Nov 09, 2005 at 03:54 UTC ( [id://506976]=note: print w/replies, xml ) Need Help??


in reply to Re: Finding Hard links
in thread Finding Hard links

Original question was about perl module... but if you start using `find` command, then:
my $original_file = '/path/to/file'; my $dir = '/where/to/find/hardlinks/'; chomp for @hard_links = `find \Q$dir\E -inum \$(find \Q$original_file\E -printf "%i")`;

Replies are listed 'Best First'.
Re^3: Finding Hard links
by blazar (Canon) on Nov 09, 2005 at 14:20 UTC

    Oh, well of course! I used an external find command because as I stressed, I just wanted to keep minimal and using File::Find, as I would most probably do in a more realistic case1, was not substantial for the technique I wanted to explore...

    You'll also notice that I used -ln on a slightly longer script than I would usually do in "production", whatever that is.

    But in the above you're fundamentally using Perl as a shell script. That is really "kinda too much". Incidentally you're using the "inner" find just to print the inode number. In that case the external stat command would suffice:

    $ stat -c %i work/ 18972756

    OTOH I didn't know about -inum, so I thank you - I know it's out there in the docs, but I tend to learn by example...

    Also, as a final observation, I think that indeed the OP was really asking about how to find hard links sharing the same inode as a given file, that is what you actually do. But if you want to search a whole directory hierarchy like I did, a "pure-find" approach along the lines of your example would be unpractical, since I think it would necessarily take two nested find's.



    1 And if I called an external find cmd, I'd probably use an explicit open.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://506976]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2024-04-18 17:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found