Alternatively you can use a simple script:
#!/bin/bash
ls -alFQ | grep '^l'
The Unix mantra is to have small simple utilities that can be chained together to achieve complex task. So while this is technically not a POSIX utility, it's very close to one.
If you want to get fancy you can only select what portion of the string to return:
#!/bin/bash
ls -alFQ | grep '^l' | tr -s ' ' | cut -d ' ' -f 11
The -f 11
returns the file the link is pointing to, and -f 10
return the name of the link.
This only works if the files names have no spaces in them, otherwise it gets tricky - it can probably be done, but you'll have to escape the white spaces or use a pattern, which is more than I care to write at the moment.
If you want something that returns 0/1:
#!/bin/bash
if [[ -n $(ls -alFQ | grep '^l') ]]; then
exit
else
exit 1
fi
file
command ? see man file