Operating System - HP-UX
1748183 Members
3634 Online
108759 Solutions
New Discussion юеВ

Re: hard link (find file , which it points to )

 
SOLVED
Go to solution
Billa-User
Regular Advisor

hard link (find file , which it points to )

hello ,

i have a hard link like (ll link_file) :
-rw-r--r-- 3 root:sys 122880 Mar 10 2003 link_file

only in the column after the permissions i can see it is a hard link ?

how can i detect the file ,where hard link "points to ?

regards
18 REPLIES 18
Milan Novak
New Member

Re: hard link (find file , which it points to )

hp@mtest:/home/hp/tmp $ ln zz zz1
hp@mtest:/home/hp/tmp $ ln zz zz2
hp@mtest:/home/hp/tmp $ ll -i zz
1639 -rwxrwx---+ 3 hp users 32 Apr 7 15:12 zz
hp@mtest:/home/hp/tmp $ find . -inum 1639 -exec ll -d {} \+
find: cannot open ./x/xx/xx
-rwxrwx---+ 3 hp users 32 Apr 7 15:12 ./zz
-rwxrwx---+ 3 hp users 32 Apr 7 15:12 ./zz1
-rwxrwx---+ 3 hp users 32 Apr 7 15:12 ./zz2
Steven Schweda
Honored Contributor
Solution

Re: hard link (find file , which it points to )

> [...] find . -inum [...]

"." may not be the best choice here. Another
linked file could be higher up the directory
tree. Better might be the mount point of the
file system containing "." (or, more
generally, the directory containing the file
of interest). And adding "-xdev" would be
good, too, because you don't want info about
other file systems, which might also use the
same inode number for unrelated files.
("find / [...]" without "-xdev" could find
many inappropriate inode matches.) So:

find -xdev -inum [...]

If there's a snappy way to determine that
mount point, then I don't know what it is.
I'd need to look at the output from "mount",
and figure it out using my brain (or a
non-trivial script). Someone else may be
more clever, though. (Or have broader
experience.)
Billa-User
Regular Advisor

Re: hard link (find file , which it points to )

thank's steven for your detail answer. maybe a perl command exists for determine the file of a hard link ? if exists in a filesystem a lot of files , maybe "find command" will run a longer time...
Earl_Crowder
Trusted Contributor

Re: hard link (find file , which it points to )

If it's a vxfs filesystem, and the disk layout version is 6 or greater, you can use vxlsino.

Dennis Handly
Acclaimed Contributor

Re: hard link (find file , which it points to )

>how can I detect the file, where hard link points to?

"ll -i" will show the inode number. First check the current directory.

>maybe a perl command exists for determine the file of a hard link?

I don't think perl will be much faster than find(1). The only thing perl can cleverly do is stop after the "3" links.

>Steven: If there's a snappy way to determine that mount point, then I don't know what it is.

bdf .
Steven Schweda
Honored Contributor

Re: hard link (find file , which it points to )

> bdf .

Ah, thanks. That easily qualifies as snappy.
(It also looks at least slightly familiar, so
I may have known it once, upon a time when I
was young (long ago).)
Hein van den Heuvel
Honored Contributor

Re: hard link (find file , which it points to )

The 'vxlsino' command, pointed out earlier, seems handy. It was new to me. Thanks!

>> how can i detect the file ,where hard link "points to ?

I believe this to be a question which only applies to softlinks.
This exact question is meaningless for hardlinks.

The way I understand it, hardlinks do not point to files, they are the file. (directory entries with a specific inode).
The moment a hardlink to a file is created, there are two indistinguishable ways to find that file (inode).

Yeah, _you_ might know which came first, but there is no information in the file system reflecting that.

So one can ask how you can detect the other entries that are in fact the same file but is makes no sense to ask which file it points to. IMHO.
The 'original' entry for the inode may long since have been removed.

fwiw,
Hein

http://en.wikipedia.org/wiki/Hard_link

# echo "Hi there" > x
# ls -il *
41317 -rw-r--r-- 1 hein root 9 Apr 23 17:36 x
# ln b x
# ln x a
# ls -il *
41317 -rw-r--r-- 3 hein root 9 Apr 23 17:36 a
41317 -rw-r--r-- 3 hein root 9 Apr 23 17:36 b
41317 -rw-r--r-- 3 hein root 9 Apr 23 17:36 x
# find . -inum 41317 -exec ls -l {} \;
-rw-r--r-- 3 hein root 9 Apr 23 17:36 ./a
-rw-r--r-- 3 hein root 9 Apr 23 17:36 ./b
-rw-r--r-- 3 hein root 9 Apr 23 17:36 ./x
# rm x
# ls -il *
41317 -rw-r--r-- 2 hein root 9 Apr 23 17:36 a
41317 -rw-r--r-- 2 hein root 9 Apr 23 17:36 b

# cat a
Hi there
# cat b
Hi there



James R. Ferguson
Acclaimed Contributor

Re: hard link (find file , which it points to )

Hi:

>how can I detect the file, where hard link points to?

You can always find the full path from which you came:

# perl -MCwd=realpath -le 'print realpath q(.)'

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: hard link (find file , which it points to )

>JRF: You can always find the full path from which you came:

That's the easy part: pwd -P
Then stick on the filename.

Everyone has been assuming the question was how to find all of the other names for that inode.