views:

159

answers:

2

Is there an easy way to show whether there are any symlinks in a specified path pointing to a certain directory or one of its children?

+2  A: 

A simple and fast approach, assuming that you have the target as absolute path (readlink(1) may help with that matter):

find $PATH -type l -xtype d -lname "$DIR*"

This finds all symlinks (-type l) below $PATH which link to a directory (-xtype d) with a name starting with $DIR.


Another approach, which is O(n*m) and therefore may take ages and two days:

find $DIR -type d | xargs -n1 find $PATH -lname

The first find lists $DIR and all its subdirectories which are then passed (xargs), one at a time (-n1), to a second find which looks for all symlinks originating below $PATH.


To sum things up: find(1) is your friend.

earl
A: 

Have a look at the findbl (bad links) script in fslint. It might give you some hints: http://code.google.com/p/fslint/source/browse/trunk/fslint/findbl

pixelbeat