Solved

Counting links pointing on a directory

Posted on 2010-09-22
5
348 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
  • 2
  • 2
5 Comments
 
LVL 76

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 76

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now