- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: resolving the source of a link
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
09-02-2004 08:17 AM
09-02-2004 08:17 AM
resolving the source of a link
I'm being told that this is impossible, but I thought that I would ask.
I need to find the source of a soft link when I know the target.
Is there any way to do this other than find commands (I need to resolve thousands of links across terabytes of data)?
Thanks.
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 08:21 AM
09-02-2004 08:21 AM
Re: resolving the source of a link
First is soft link and 2nd the source
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 08:25 AM
09-02-2004 08:25 AM
Re: resolving the source of a link
Thanks.
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 08:33 AM
09-02-2004 08:33 AM
Re: resolving the source of a link
I don't think that information is kept anywhere - not in an inode, or stat.......etc...
You have a directory (or file) and want to know if there are any symbolic (or hard) links to it.
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 08:38 AM
09-02-2004 08:38 AM
Re: resolving the source of a link
ls -L file
If it has links, it will display source file and not the link.
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 08:41 AM
09-02-2004 08:41 AM
Re: resolving the source of a link
If the argument is a symbolic link, list the file or
directory to which the link refers rather than the link
itself.
What Alan want, is a list of all symblic links pointing to a particular directory.
Example:
/oracle is a mount point and a directory.
What (if any) symbolic links out on the system are pointing to it?
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 08:45 AM
09-02-2004 08:45 AM
Re: resolving the source of a link
Say SOFTLINK is linked to FILE then
# ls -l SOFTLINK
will tell which file it is linked to
but there is no way to trace SOFTLINK from FILE except ofcourse by using find.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 08:51 AM
09-02-2004 08:51 AM
Re: resolving the source of a link
Say you have the following:
# ll test
lrwxr-xr-x 1 root sys 16 Sep 2 15:47 test@ -> security_catalog
He wants to be able to run a command on the file security_catalog and determine that test links to security_catalog.
I agree with the other folks above, I don't think this is easily doable. The only thing I can really think of is 'find /dir -type l -exec ll -d {} \;'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 08:56 AM
09-02-2004 08:56 AM
Re: resolving the source of a link
How about using find?
find /start_point -type l -exec ls -l {} \; | grep "/full/path/to/target"
Note - this may put a hammer on the system whilst it runs. But it should work
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 09:10 AM
09-02-2004 09:10 AM
Re: resolving the source of a link
But tllist lists only the transitional links.
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 09:19 AM
09-02-2004 09:19 AM
Re: resolving the source of a link
No guarantees. Your mileage may vary. Etc, etc.
I used the /etc directory as my test case. Modify it to fit your needs.
#!/usr/bin/sh
find /etc -type l | xargs ll | awk '{print $11,$9}' > /home/root/link_list
cat /home/root/link_list | sort > /home/root/link_list1
while read ORIGFILE LINK
do
if [ "${FILE}" != "${ORIGFILE}" ] ; then
echo ""
echo ""
echo "${ORIGFILE} has the following links pointing to it: "
echo "${LINK}"
else
echo "${LINK}"
fi
FILE=${ORIGFILE}
done < /home/root/link_list1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 09:23 AM
09-02-2004 09:23 AM
Re: resolving the source of a link
I'm running find commands now to build a list of the regular files.
Unfortunately, I will have to resolve the information I need via a ctree database, so it will be slow going.
Thanks again.
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2004 05:46 PM
09-02-2004 05:46 PM
Re: resolving the source of a link
May we assume you have fewer links then actual files?
Why would you want a (large) list of all real files if all you seem to want is the real files which are being pointed to?
Anyway... it does not seem to be a trival problem. I could not find a 'handy' command to really follow a link down to a path.
Sure, 'ls -l' and the readlink function will show the softlink, but that may well be relative! Like: ../../xxx/yyy/realfile.dat
There is some shell code to do this, for example see:
http://www.kaffe.org/pipermail/kaffe/1998-September/086554.html
But what I liked best was a perl solution as per:
http://www.stonehenge.com/merlyn/UnixReview/col27.html
I'll attach the working code for that.
I _think_ it solves your problem if you use it with for example:
find /etc -type l -exec perl follow.p {} \; | sort -k 3 > links.lst
Then you can grep the resulting links.lst for the real file names.
It is NOT fast.
If I needed this, then I would probably modify it to an all perl, single activation, solution using 'glob' and the '-l' test.
Sample output below, followed by code (also attached).
Hope this helps...
Hein.
/etc/snmpd.conf is /etc/SnmpAgent.d/snmpd.conf
/etc/checklist is /etc/fstab
/etc/aliases is /etc/mail/aliases
/etc/dce_com_env is /etc/opt/dce/dce_com_env
/etc/dce_com_utils is /etc/opt/dce/dce_com_utils
/etc/dce_config_env is /etc/opt/dce/dce_config_env
/etc/dce_config_utils is /etc/opt/dce/dce_config_utils
/etc/opt/gnome/gtk/gtkrc.be is /etc/opt/gnome/gtk/gtkrc.cp1251
/etc/opt/gnome/gtk/gtkrc.bg is /etc/opt/gnome/gtk/gtkrc.cp1251
/etc/opt/gnome/gtk/gtkrc.he_IL.cp1255 is /etc/opt/gnome/gtk/gtkrc.cp1255
/etc/opt/gnome/gtk/gtkrc.he_IL.microsoftcp1255 is /etc/opt/gnome/gtk/gtkrc.cp1255
/etc/opt/gnome/gtk/gtkrc.yi is /etc/opt/gnome/gtk/gtkrc.cp1255
/etc/opt/gnome/gtk/gtkrc.lt is /etc/opt/gnome/gtk/gtkrc.iso-8859-13
/etc/opt/gnome/gtk/gtkrc.lv is /etc/opt/gnome/gtk/gtkrc.iso-8859-13
/etc/opt/gnome/gtk/gtkrc.mi is /etc/opt/gnome/gtk/gtkrc.iso-8859-13
/etc/opt/gnome/gtk/gtkrc.cy is /etc/opt/gnome/gtk/gtkrc.iso-8859-14
/etc/opt/gnome/gtk/gtkrc.ga is /etc/opt/gnome/gtk/gtkrc.iso-8859-14
:
use File::Find;
use Cwd;
find sub {
my $dir = cwd;
exit 1 unless -l;
my @right = split /\//, $File::Find::name;
my @left = do {
@right && ($right[0] eq "") ?
shift @right : # quick way
split /\//, $dir;
}; # first element always null
while (@right) {
my $item = shift @right;
next if $item eq "." or $item eq "";
if ($item eq "..") {
pop @left if @left > 1;
next;
}
my $link = readlink (join "/", @left, $item);
if (defined $link) {
my @parts = split /\//, $link;
if (@parts && ($parts[0] eq "")) { # absolute
@left = shift @parts; # quick way
}
unshift @right, @parts;
next;
} else {
push @left, $item;
next;
}
}
print "$File::Find::name is ", join("/", @left), "\n";
}, @ARGV;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2004 12:29 AM
09-03-2004 12:29 AM
Re: resolving the source of a link
You have file B,C,..
1. Find all files that are links.
2. Run ls -ld on each file.
(find / -type l -print | xargs ls -ld > big.txt)
3. Use the resultant output (i.e. big.txt) to make a perl hash. The key is the fake, link file. The value is the real file that the link is pointing too.
You can't do this on the fly during the day. You have lots of stuff running. This could take hours. So find all the links via a cronjob in the middle of the night.
Ok you ran it once. Now run it each night for just the changes in the last 24 hours.
find / -type l -mtime -1 -print | xargs ls -ld >> bigchanges.txt
Now as far as the details in coding? I'd listen to the other folks here. I'm just trying to tell you there IS a way to get what you want. It would just take some planning to process through terabytes of filesystem.
Oh and be careful to the size of the results. You would not want your big report to exceed the size of the filesystem it sits
on in the middle of the night.
Ok one more SILLY note. One time I had a simple command like "tail -20 bigfile" FAIL because of kernel limits in passing through the pipe command. There are limits to the number of arguments allowed for xargs. There are limits to the length of an arguments. This happened to me a number of years ago. But it was like using physics when approaching the speed of light. What you think is normal is strangely askew. IF this is the case, look into busting the job up into pieces.
Steve