On 08/05/07, Matthew Hannigan <[EMAIL PROTECTED]> wrote:

On Mon, May 07, 2007 at 01:31:16PM +1000, Amos Shapira wrote:
>
> What about "find -L -samefile give-target"?
>
> e.g.
>
> $ touch target
> $ ln -s target link-to-target
> $ ls -l
> total 0
> lrwxrwxrwx ... link-to-target -> target
> -rw-r--r-- ... target
> $ find -L -samefile target
> ./target
> ./link-to-target

Nice!  I was about to suggest using
        find . -exec ls -ldiL {} \;
then grepping/parsing the result for the inode
but using find's nibuilt features is better.

(for ls, i says show the inode number, L means resolve links)


I too wasn't aware of this particular option either, I was more after trying
to find the inode+device numbers of all files pointed to by symbolic links
then compare these to the given file, then I found this when I looked
through find(1). Be aware that i-node numbers are not unique across
filesystems so you have to compare the device number too ("%D" in find's
-printf), which is exactly what -samefile does.

IMHO - using find is generally better since it saves you ls's inefficient
read/sort/print tons of text that isn't going to be looked at (I felt this
not long ago when I had to shuffle around directories with thousands of
files in them - perl opendir() is such a godsend :). If you must use ls(1)
then a little optimization could be the use of "-f" to avoid it sorting its
output.

Cheers,

--Amos
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to