shell 如何找到没有软链接的目录?[已关闭]

lbsnaicq  于 12个月前  发布在  Shell
关注(0)|答案(3)|浏览(108)

已关闭此问题为not about programming or software development。它目前不接受回答。

这个问题似乎不是关于a specific programming problem, a software algorithm, or software tools primarily used by programmers的。如果你认为这个问题与another Stack Exchange site的主题有关,你可以留下评论,解释在哪里可以回答这个问题。
上个月关门了。
Improve this question
我有一个目录包含几个子目录:

./abc/
./cde/
./link_to_abc -> ./abc

abc和cde是普通目录,而link_to_abc是一个目标为abc的软链接。
现在我想使用Linux的find命令来查找没有软链接的普通dir,在我的例子中,它是cde。怎么做?
因为我需要删除一些目录,但我应该检查没有人使用我的文件了(没有其他符号链接指向我的目录)

hkmswyz6

hkmswyz61#

以下解决方案使用多个find,但应该可以工作:

# step1: list all directories:
$ find /absolute/path -type d | sort > real_dirs.txt
# step2: list all files "pointed" by a symlink:
$ find /absolute/path -type l -exec readlink -f {} \; | sort > sym_dirs.txt
# step3: get directories not "pointed" by symlinks:
$ comm -23 real_dirs.txt sym_dirs.txt
txu3uszq

txu3uszq2#

使用find ! -type lfind -type d
检查此答案https://stackoverflow.com/a/16303559/3343045

ef1yzkbh

ef1yzkbh3#

如果只有一个符号链接要排除,请使用以下方法:

find -H /dir -mindepth 1 -maxdepth 1 -type d ! -samefile "/dir/link_to_abc"

这将查找/dir下的所有文件夹,指定符号链接指向的文件夹除外。

相关问题