• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

Command to find Symbolic links in Linux

How do I find symbolic links that are broken or incorrect in Linux? Thanks!
0
Rhiaanon44
Asked:
Rhiaanon44
  • 2
2 Solutions
 
point_pleasantCommented:
find -L . -type l -lname ‘*’
0
 
point_pleasantCommented:
or
with bash this dones nice highlighting of the file name
find . -type l | (while read linkname ; do test -e "$linkname" || ls -ld "$linkname"; done)
0
 
dfkeCommented:
To list broken links:

for f in $(find /path/to/dir -type l); do if [ ! -e "$f" ]; then echo "$f"; fi; done

To find where they are linked to:

find /path/to/dir -type l | while read f; do if [ ! -e "$f" ]; then ls -l "$f"; fi; done`

To remove them:

find /path/to/dir -type l | while read f; do if [ ! -e "$f" ]; then rm -f "$f"; fi; done

Please note that removing is without confirmation.
0
 
Rhiaanon44Author Commented:
Thank you both for expert help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now