我可以检查文件是否存在,是否是带有-L的符号链接
for file in *; do
if [[ -L "$file" ]]; then echo "$file is a symlink"; else echo "$file is not a symlink"; fi
done
如果它是带有-d的目录:
for file in *; do
if [[ -d "$file" ]]; then echo "$file is a directory"; else echo "$file is a regular file"; fi
done
但是,如何仅测试目录链接?
我在测试文件夹中模拟了所有案例:
/tmp/test# ls
a b c/ d@ e@ f@
/tmp/test# file *
a: ASCII text
b: ASCII text
c: directory
d: symbolic link to `c'
e: symbolic link to `a'
f: broken symbolic link to `nofile'
shopt -s dotglob