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?
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.
Following up on the answer given by earl:
-xtype
does not work on Mac OSX, but can be safely omitted:
find $PATH -type l -lname "$DIR*"
Example:
find ~/ -type l -lname "~/my/sub/folder/*"
-xtype
is used to find symbolic links when -L
(old days -follow
) is on. -xtype
is afaik is a GNU extension. And you are correct. It can be safely omitted since -L
is not used. One think though -type d
will give directories only and -type l -type d
will give symbolic links to directories only. –
Angkor 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
© 2022 - 2024 — McMap. All rights reserved.