How do I know which hard link belongs to which file. I can't seem to find
a command that will tell me this. Any help on this matter would greatly
be appreciated.
Keith Boruff
How do I know which hard link belongs to which file. I can't seem to find
a command that will tell me this. Any help on this matter would greatly
be appreciated.
Keith Boruff
> How do I know which hard link belongs to which file. I can't seem to find
> a command that will tell me this. Any help on this matter would greatly
> be appreciated.
--
Alan H. Katz | MJ Research, Inc.
617-370-8128 | Watertown, MA 02172
|
Again, thanks..
Keith Boruff
>> Use ls -i to find the inode of the file in question and then use find to
>> find all files with the same inode.
>Thanks Alan. From the material that I have read about hard links, two
>files linked to each other share the same internal file (inode). I just
>want to be able to keep track of any hard links that I create.
#!/bin/csh
cd /
tar -cvf /dev/null ./* \
| grep " link to " \
| awk '{printf("The file %s is linked to %s\n",$2,$5)}' > linked.files
This will give you a list of all files on your system that are linked to another
file. This will include both hard and symbolic links. I also have another one that
lists them the other way around with
printf("The file %s is linked with %s\n",$5,$2)
that I can pass through sort to give me a list of files with it's associated link
points.
Is it a cpu hog? You bet. Is there a better way to do it? I sure hope so!
Use: ls -i
This will print the inode with each file. Any files with the same inode
are hard linked.
Or on some flavors of unix (works on HP, not on Sun) you can use:
find path -linkedto filename
Tom Sanders
Lee> If you *really* want to know what files are linked to each other, then try this
Lee> little cpu-cycle-killer on for size:
Lee> #!/bin/csh
Lee> cd /
Lee> tar -cvf /dev/null ./* \
Lee> | grep " link to " \
Lee> | awk '{printf("The file %s is linked to %s\n",$2,$5)}' > linked.files
Or something a little less cpu-killing:
#!/usr/bin/perl
use File::Find;
find( \&wanted, '/' );
sub wanted {
my $name = $File::Find::name;
my ($dev,$ino) = lstat;
if (exists $seen{$dev,$ino}) {
print "$name is linked with $seen{$dev,$ino}\n";
} else {
$seen{$dev,$ino} = $name;
}
}
In fact, when I last checked, File::Find::find runs faster than SunOS
find(1). :-)
Just another Perl hacker,
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Web: <A HREF="http://www.teleport.com/~merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
HI All,
I have a question regarding hard/soft link. in unix/linux file system, I
just know some basic diffirent between hard/soft link. I check system like
solaris/redhat/bsd. the solaris used lots of hard link, the most is 27 hard
links.
Who can tell me some details what is real advantage using hardlink.
Thanks
Jaff
4. Why doesn't Microsoft release a Linux distro?
6. How to declare USB PORT under SCO 3.2V4.2
7. A hard link or a symbolic link?
8. Q: SCSI MO disk and extra hard-disk
9. Hard link to sym link - how to make?
11. hard links and symbolic links
13. What is the difference between soft link and hard link?