coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coreutils] How to figure out all the hard links that link to the sa


From: Eric Blake
Subject: Re: [coreutils] How to figure out all the hard links that link to the same file?
Date: Tue, 27 Jul 2010 06:01:25 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100720 Fedora/3.1.1-1.fc13 Lightning/1.0b2pre Mnenhy/0.8.3 Thunderbird/3.1.1

On 07/27/2010 01:30 AM, wayana wrote:
> Hello,
> 
> How about using 'find' ?
> 
> $ find -inum $(ls -i a | cut -d ' ' -f 1)
> ./b
> ./a

That assumes they are in the same directory.  But in reality, the other
link can be anywhere within the same device, so you need to figure out
where the mount point is that contains ./a (I don't know of any tool
that makes this easy, other than recursively checking devno of ., ..,
and so forth until you find a difference), then use find -xdev to
traverse the entire device looking for that -inum.  In general, not a
trivial or fast operation.

Also, if you assume GNU utilities, $(stat -c %i a) is more efficient
than $(ls -i a | cut -d ' ' -f 1).

Maybe the coreutils _should_ provide an easy way to get at the mount
point that contains a given file (or which errors out because
permissions don't allow determining that information).  But would that
belong under stat(1), or some other tool?

-- 
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]