?
Solved

Counting links pointing on a directory

Posted on 2010-09-22
5
Medium Priority
?
356 Views
Last Modified: 2012-05-10
Hi!
I have a web server running which is shared among different clients (aka unix users). In a commonly available directory I have stored some php libraries which are used (linked to) by some of the users. As time passes some of the libraries are outdated (but still stored on the server) and I want to delete those folders containing libs that are not linked by ANY user.

Problem is: I am not root on the server and cannot access the user dirs. How can I find out if there is still a link to a certain directory (maybe even number of "active" links) so that I can delete folders no longer needed?

What I tried: Locate links by using "find / -lname /path/filename" which does NOT work because I cannot access the user dirs.

Any suggestions?

CU
 maxhb

P.S.: OS is FreeBSD and Debian(Lenny)
0
Comment
Question by:max-hb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 79

Expert Comment

by:arnold
ID: 33738603
an entry next to the file indecate how many hard references there are
access_rights number_of_links owner group size date filename.

There is no way to know which are active since the libraries are included in the PHP code and are loaded on the server.
0
 
LVL 4

Author Comment

by:max-hb
ID: 33738667
Hi!
When speaking about "active" I mean that there exists at least one link in the filesystem pointing to a file/folder.
I totally understand that evaluating php code is beyond the scope of linux shell commands ;-)

To make it simple: How to find the number of (soft) links pointing to a certain file/folder when not having the option to search the entire file system.

CU
 maxhb
0
 
LVL 2

Accepted Solution

by:
madan1278 earned 750 total points
ID: 33740314
Identifying soft links without having proper access to user file systems will make it simply impossible as the link could span across multiple file systems.

If its a hardlink you can simply find with the inum option in the find command as shown below. I assume 12345 is the inum of the target file or directory.
find /xyz -inum 12345

Assuming you have the root access dump the links extract to a temp file and grep for the required patterns to figure out the list of soft links thats pointing to the named pattern.

find /xyz -type l -print > /tmp/link_extract
for each in `cat /tmp/pattern_list`
grep $pattern /tmp/link_extract > /dev/null
if [ $? -eq 0 ]
then
echo "soft Link match found - $pattern"
fi
done
0
 
LVL 79

Expert Comment

by:arnold
ID: 33740651
Not sure why you have users link to libraries rather than configure the libraries to be accessible through PHP.

/usr/local/lib/php

Not sure why there is a need for user to have a ln -s /somelocation/somepath/somephp_library local_link.

Do the old libraries have some issues that leads you to delete them?
If so, notify the user base saying on such and such a date following security/other considerations, the following libraries will no longer be available.
Or a newer version will be installed on the OS and configure it to be accessible by all and that should be the end of it and the future ever growing symbolic link references...

0
 
LVL 4

Author Closing Comment

by:max-hb
ID: 33742737
I was hoping to hear that counting links would be possible, but sometimes we have to accept our limits ;-)
0

Featured Post

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Utilizing an array to gracefully append to a list of EmailAddresses
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question