Solved

Counting links pointing on a directory

Posted on 2010-09-22
5
350 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 77

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 77

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cygwin VIM in WIndows 2007: Unable to copy text to Windows 10 65
linux(debian) mouse poor performance 4 39
awk sed 8 39
awk sed variable in file 3 34
If you use Debian 6 Squeeze and you are tired of looking at the childish graphical GDM login screen that is used by default, here's an easy way to change it. If you've already tried to change it you've probably discovered that none of the old met…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

816 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

9 Experts available now in Live!

Get 1:1 Help Now