Bash – How to Find All Soft Links in Current Directory

bashlnlsshell-scriptsymbolic-link

Question relates to shell-scripting in bash.

How to check with a script which files within the current directory are soft links?

In case I have used the wrong term, when I say soft links, I am referring to files created using ln -s.

The only thing I have managed to think of is to evaluate ls -la as an expression, and parse its results, but obviously this is not the best solution.

Best Answer

See 'CONDITIONAL EXPRESSIONS' in man bash – in this case you want -h:

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