I have a directory that has symbolic links - some of them point to files and some of them to directories - how do I identify the ones poiting to directory in a shell script ( without any prejudice to names offcourse)
Asked
Active
Viewed 1,135 times
1
-
1Use `readlink` to get the target of the symlink. – Sneftel May 08 '14 at 12:44
-
Thanks. ls -L and ls \`readlink \` seem to be identical – Yogesh Devi May 08 '14 at 13:12
1 Answers
1
use ls -L option to follow symlinks
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
![](../../users/profiles/1529301.webp)
Yogesh Devi
- 437
- 5
- 22