I can use
find /search/location -type l
to list all symbolic links inside /search/location.
How do I limit the output of find
to symbolic links that refer to a valid directory, and exclude both, broken symbolic links and links to files?
directoryfindsymlink
I can use
find /search/location -type l
to list all symbolic links inside /search/location.
How do I limit the output of find
to symbolic links that refer to a valid directory, and exclude both, broken symbolic links and links to files?
Best Answer
With GNU find (the implementation on non-embedded Linux and Cygwin):
With find implementations that lack the
-xtype
primary, you can use two invocations offind
, one to filter symbolic links and one to filter the ones that point to directories:or you can call the
test
program:Alternatively, if you have zsh, it's just a matter of two glob qualifiers (
@
= is a symbolic link,-
= the following qualifiers act on the link target,/
= is a directory):