3

查找断开的符号链接

 2 years ago
source link: https://www.lujun9972.win/blog/2020/01/24/%E6%9F%A5%E6%89%BE%E6%96%AD%E5%BC%80%E7%9A%84%E7%AC%A6%E5%8F%B7%E9%93%BE%E6%8E%A5/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

查找断开的符号链接

今天看 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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK