[英]How to determine if a linux symbolic link points to a directory or a file
我有一个包含符号链接的目录-其中一些指向文件,而另一些指向目录-如何在shell脚本中识别那些指向目录的链接(不影响名称无关紧要)
use ls -L option to follow symlinks 使用ls -L选项跟随符号链接
This is the script that I used to differentiate between directories with contents from files/empty directories ( this will work only if directory has some contents -- in my case I am anyway interested in those directories that have some content so I am happy - but do suggest better options if any 这是我用来区分包含文件/空目录内容的目录的脚本(仅当目录包含某些内容时,此脚本才起作用-就我而言,我对那些包含某些内容的目录很感兴趣,因此我很高兴-但是如果有的话,建议更好的选择
cd dir
for i in `ls `
do
if [ 1 -lt `ls -l -L $i | wc -l` ]
then
echo "$i is a non empty directory"
else
echo "$i is either an empty directory or a file"
fi
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.