- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- hard link (find file , which it points to )
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2011 10:35 PM
04-20-2011 10:35 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2011 10:57 PM
04-20-2011 10:57 PM
Re: hard link (find file , which it points to )
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2011 03:43 AM
04-21-2011 03:43 AM
Solution"." 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
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.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2011 04:12 AM
04-21-2011 04:12 AM
Re: hard link (find file , which it points to )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2011 05:29 AM
04-21-2011 05:29 AM
Re: hard link (find file , which it points to )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2011 06:58 AM
04-23-2011 06:58 AM
Re: hard link (find file , which it 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 .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2011 12:39 PM
04-23-2011 12:39 PM
Re: hard link (find file , which it points to )
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).)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2011 01:33 PM
04-23-2011 01:33 PM
Re: hard link (find file , which it points to )
>> 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2011 09:39 AM
04-24-2011 09:39 AM
Re: hard link (find file , which it points to )
>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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2011 02:23 PM
04-24-2011 02:23 PM
Re: hard link (find file , which it points to )
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2011 02:42 AM
04-28-2011 02:42 AM
Re: hard link (find file , which it points to )
does a command or function exits like "get filesystem " ?
a combination of "pwd -P" and "bdf ." ?
i think it is better to user "df ." , why?
when i have longer lvol's oder filesystem's, it isn't easy to parse :
df .
/testfs/filesys1 (/dev/vgtestfs1/filesys1): 12205184 blocks 191869 i-nodes
bdf .
Filesystem kbytes used avail %used Mounted on
/dev/vgtestfs1/filesys1
18874368 12734552 6102592 68% /testfs/filesys1
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2011 03:23 AM
04-28-2011 03:23 AM
Re: hard link (find file , which it points to )
i created a short script (in attachment).
it is a mix of shell and perl.
i use perl to detect :
- nlink number of (hard) links
- inode number
how can i detect the version of filesystem
- i use /sbin/vxupgrade ?
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2011 04:08 AM
04-28-2011 04:08 AM
Re: hard link (find file , which it points to )
A couple of comments:
If you to see if a directory is a mountpoint, test [stat()]for the directory to have an inode number of <2>. All mountpoints have inode=2.
I suggested using :
# perl -MCwd=realpath -le 'print realpath q(.)'
...to be able to define (at the top level) the mountpoint in which you are looking.
As for detecting the VxFS filesystem version, you can use the device associated with the filesystem in question :
# fstyp -v /dev/vgNN/lvolN
...or you can use 'vxupgrade':
# vxupgrade /mymountpoint
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2011 05:50 AM
04-28-2011 05:50 AM
Re: hard link (find file , which it points to )
# perl -MCwd=realpath -le 'print realpath q(.)'
should i get the mountpoint in which i am ?
we have at one server following mountpoint's:
/testfs
/testfs/filesys1
/testfs/filesys2
when i change to example:
cd /testfs/filesys1/dir1/dir2
then i get with :
perl -MCwd=realpath -le 'print realpath q(.)'
/testfs/filesys1/dir1/dir2 .
should i get /testfs/filesys1 ?
on other server i have a filesystem like:
/demo
i change to /demo/dir1/dir2
then i get with :
perl -MCwd=realpath -le 'print realpath q(.)'
/demo/dir1/dir2
perl -MCwd=realpath -le 'print realpath q(.)'
is it only for link's ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2011 06:17 AM
04-28-2011 06:17 AM
Re: hard link (find file , which it points to )
> please correct if i don't understand command:
I'm sorry, I don't mean to be oblique. My thinking is that if you have the full, real path of your file, then you can walk-backwards through the (sub)paths using a stat() to find at what point you are inode=2 which is the mountpoint.
Knowing the mountpoint then allows you to use a find() by inode. Listing all files in a filesystem with the same inode gives you what you want.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2011 02:52 PM
04-29-2011 02:52 PM
Re: hard link (find file , which it points to )
No need when you can roll your own.
How often are you going to track down these hardlink families that you think you need a script?
>I think it is better to user "df ."
My fingers just always type bdf. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2011 12:38 AM
05-02-2011 12:38 AM
Re: hard link (find file , which it points to )
in my company we have a self-developed application , with use hard link's. i had to check if the hard link's point to the right source. how many hard link's : about 6.000
with the script i would know very fast , where the hard link "point to"
i checked the hard link's with those little script and it work's with your input perfect.
thanks
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2011 12:55 AM
05-02-2011 12:55 AM
Re: hard link (find file , which it points to )
final version of script:
get_file_of_hard_link.sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2011 11:08 AM
05-02-2011 11:08 AM
Re: hard link (find file , which it points to )
If you have 6 thousand links to check, you may want to do more than one at a time.