List symlinks in current directory

findlssymlink

This question talks about finding directories in a current diretory. The solution is basically:

ls -d */

That's great but how can I easily list symlinks? Do I have to use something like

find . -xtype l -d 1
(intended to find symlinks max depth 1 - doesn't work)

Or is there an easier way? Can ls be used for this?

Best Answer

In zsh (add N inside the parentheses to include symlinks whose name begins with a .):

echo *(@)

With most find implementations:

find -maxdepth 1 -type l

POSIX-compliant:

find . -type d \! -name . -prune -o -type l -print

Or with a shell loop:

for x in * .*; do
  if [ -h "$x" ]; then echo "$x"; done
done
Related Question