>_ IzzyLab

Hands-on task

This task is step 6 of the course “Disks, links and free space”

Clean up broken symbolic links

medium~5 min

The /root/links directory is littered with symbolic links: some point to existing files, and some are "dangling" — their target was deleted. Delete all broken (dangling) symbolic links without touching the working links and regular files.

What you'll practise:
  • symbolic links
  • find
  • -xtype
  • broken links

Topic breakdown

A symbolic link stores a path to its target, not the data itself; if the target is deleted, the link becomes "dangling" — it exists but leads nowhere. find can tell working links apart from broken ones via type tests: the ordinary -type looks at the object itself, but there's a separate test that dereferences the link and checks what the target turned out to be. Combining such a selection with deletion lets you purge only the dead links without touching the live ones and regular files.

What's checked

  1. no broken links remain
  2. working links and file intact

What it looks like