Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想获取具有有效链接的目录中所有符号链接的列表。换句话说,我希望在我的列表中丢弃所有损坏的链接。
在 shell 中,[ -L "$f" ] && [ -e "$f" ]当且仅当 "$f" 是其目标存在的符号链接的名称时为真。所以:
[ -L "$f" ] && [ -e "$f" ]
for f in *; do if [ -L "$f" ] && [ -e "$f" ]; then # do something with "$f" fi done
(永远不要对/ ...使用-aor-o选项;不能依赖它们来获得合理的优先级。)test[]
-a
-o
test
[
]