1

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)

Yogesh Devi
  • 437
  • 5
  • 22

1 Answers1

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
Yogesh Devi
  • 437
  • 5
  • 22