Ask a Question related to Linux / Unix Administration, Design and Development.
-
olyathe #1
How to find hard links
For symbolic links, we can issue "ls -l" command to see the file the
link points to. Is there any command to see the file the hard link
point to?
I know we can issue "ls -i" command to find the inode number of the
file with the hard links and compare with the inode of the file it
points to. But if I don't know the file the hard link points to, how
to know the file it points to?
Another question: Is there a way to find the symbolic links and hard
links that associates with a file?
Thank you!
olyathe Guest
-
Looking for hard to find mac software?
I have a very extensive collection of ac Software and I have always believed in the concept of sharing, if you are in need of something just e-mail... -
Find Links in a html file
Hello, Can anyone help me with the following problem I want to make an ASP page look at my index.html file, and give me a list of all the... -
Will File::Find::Rule follow symbolic links?
Is there a way to tell File::Find::Rule to follow symbolic links? Neither "follow" nor "follow_fast" appear to be methods. I couldn't set... -
find the free hard disk space
EXEC master..xp_fixeddrives "Abraham" <binu_ca@yahoo.com> wrote in message news:eT1ZmpYRDHA.304@tk2msftngp13.phx.gbl... -
?Hard links, Soft links, & Aliases--Explain
Hi All, Could some knowledgeable UNIX type please explain the differences between hard links, soft links, and traditional Mac aliases. Responses... -
Lew Pitcher #2
Re: How to find hard links
olyathe wrote:
For all intents and purposes, you /are/ seeing the file the hard link points> For symbolic links, we can issue "ls -l" command to see the file the
> link points to. Is there any command to see the file the hard link
> point to?
to. With hardlinks, there is no one 'original' or 'root' file; all hardlinks
share that responsibility equally. In this view, the /inode/ is the 'file';
the hardlinks are just alternate /routes/ to the file.
This is a nonsensical question; it assumes that there is some heirarchy of> I know we can issue "ls -i" command to find the inode number of the
> file with the hard links and compare with the inode of the file it
> points to. But if I don't know the file the hard link points to, how
> to know the file it points to?
ownership between different directory entries pointing to the same inode.
Perhaps you really mean "how do I find out what other directory entries
point at the inode of a specific directory entry?".
Recurse through the directory hierarchy, looking at files and symlinks,> Another question: Is there a way to find the symbolic links and hard
> links that associates with a file?
resolving each symlink into a file.
If the file's inode matches the inode of the target file, then the test file
points to the target file.
> Thank you!
--
Lew Pitcher, IT Consultant, Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)
Lew Pitcher Guest
-
Chris Mattern #3
Re: How to find hard links
olyathe wrote:
Hard links don't "point to another file" the way symbolics links do.> For symbolic links, we can issue "ls -l" command to see the file the
> link points to. Is there any command to see the file the hard link
> point to?
>
> I know we can issue "ls -i" command to find the inode number of the
> file with the hard links and compare with the inode of the file it
> points to. But if I don't know the file the hard link points to, how
> to know the file it points to?
>
> Another question: Is there a way to find the symbolic links and hard
> links that associates with a file?
>
Hard links are the basic mechanism by which filenames point to the
i-node where the file is kept. If you hard link a filename to another
file, what you are actually doing is pointing that filename at the
i-node. After the link is made, *both* filenames are equal--neither
one points at the other, they both point to the same i-node. Delete
either filename and the file will continue to exist under the other name.
You can find all the filenames that point to a given i-node with the
find command. Remember that i-node numbers are only unique within a
filesystem (that's why hard links can't cross file systems), so you'll
need to limit your find to the file system in question.
Chris Mattern
Chris Mattern Guest
-
FLP #4
Re: How to find hard links
For hard links, it is quite easy :
- you note the inode number of the file
- you 'cd' to the mount point of the file system
- and you use : find . -inum <your inode number>
(with '-xdev' if you have embedded mount points in this filesystem)
To find hard links to regular files :
- find . -type f -links +1
Finding hard links to directories is much harder and I don't know how to do
it with the shell only. But, making hard links to directory is certainly the
worst idea a Unix admin can have and there shouldn't be any on your system.
To find all the symbolic links that point to a specific file :
- Note the inode number of your file. If your file is itself a symbolic
link, use 'ls -Ldi'
- find / -follow -inum <your inum>
The problem is that symbolic links can cross device boundaries and relying
on the inode number is not enough because, with the previous command, you
can get a file whose inode number is the same as your one, but in a
different file system. An alternate method could be :
file=<your target file>
inum=`ls -Ldi $file | awk '{ print $1 }'`
for i in `find / -type l`
do
[ $inum = `ls -Ldi $i | awk '{ print $1 }'` ] || continue
echo $i
done
This way, you check only the symbolic links and the probability to find the
same inode in a different filesystem is lower, but it is still not perfect,
and it is much slower. The best solution would certainly be using the
'realpath' facility in perl or C, or finding an other way to get the
'st_dev' field of the stat(2) system call.
And, if you like it, there is a much harder problem : how to find all the
symbolic links of the system who depend on a given symbolic link for their
final resolution ? This one, I think that it cannot be solved with a shell
script and, even with a C or perl program, it is not simple.
FLP Guest



Reply With Quote

