Solved

Counting links pointing on a directory

Posted on 2010-09-22
5
353 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 78

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 250 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 78

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

691 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