How to get a list of symbolic links excluding broken links?

I managed to find a command to get a list of broken links, but not "working" symbolic links

find -H mydir -type l

How can I do the opposite?

If I have these files in mydir:

foo
bar
bob
carol

If these are all symbolic links, but bobpoint to a file that does not exist, I want to see

foo
bar
carol
+5
source share
3 answers

C find(1)use

$ find . -type l -not -xtype l

, - . ( , , . -xtype f -not -xtype l, , .)

$ find . -type l -not -xtype l -ls

, .

, zsh :

% echo **/*(@^-@)

: glob @ , ^-@ " not (^)) (@), (-).

(. python, , Linux. . , .)

+4

(LINUX) , , :

find DIR1 -type l -xtype f -ls

"find" (LINUX) xtype: " -xtype , -type "

:

find DIR1  -type l -xtype d -ls
+2

bash:

find . -type l -print | while read src
do
    [[ -e "$src" ]] && echo $src
done

, , →

+1

All Articles