Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Counting links pointing on a directory

Posted on 2010-09-22
5
Medium Priority
?
359 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 80

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 80

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

604 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