查找断开的符号链接
今天看 man find 的时候发现了一个 xtype 选项。
-xtype c
The same as -type unless the file is a symbolic link. For symbolic links: if the -H or -P option was specified, true if the file is a link
to a file of type c; if the -L option has been given, true if c is `l'. In other words, for symbolic links, -xtype checks the type of the
file that -type does not check.
也就是说,可以通过 -xtype l 来搜索断开的符号链接,像下面这样
export TMPDIR=/tmp/test ln -s $(mktemp --dry-run) $(mktemp --dry-run) find ${TMPDIR} -xtype l
/tmp/test/tmp.I6YuQ7Y7he
