You don’t have to crawl directories manually to find symlinks. Combined, find, readlink, stat, and file can pinpoint them. All commands below were tested on WSL2.
1. TL;DR: Find Links by Use Case
- Find all symlinks:
find /path -type l, recursive full scan. - See where a link points:
readlink <link>, prints the target directly. - Check broken links:
find /path -xtype l, filters out invalid links.
2. find: Recursively Search for Symlinks
find /tmp -type l -name "*.conf"
find /tmp -xtype l
find /home -type l 2>/dev/null
find recursively walks the directory tree; -type l restricts matches to symbolic links [1]. -xtype l matches broken links (dangling or pointing to a missing target). Add 2>/dev/null to suppress permission errors.
3. readlink: Print the Link Target
readlink /path/to/link
readlink -f /path/to/link
readlink prints the raw target of a symlink. Add -f to resolve every path component and return the absolute real path [2]. If the target is missing, -f returns nothing—use it to spot broken links quickly.
4. stat: Inspect File Type and Device
stat /path/to/link
file /path/to/link
stat shows the file type and inode. A symlink’s output will include -> pointing to the target [3]. file also labels it as symbolic link to .... Both work without following the link by default.
5. Batch Check: Find + readlink
find /etc -type l -exec readlink -f {} \;
Pipe find results into readlink -f to see every link’s resolved target on one line. Replace -exec with xargs for faster bulk processing.
6. Notes and Limitations
readlink -frequires the target to exist; it returns nothing for broken links.- WSL2 stores Linux symlinks as Windows reparse points; some Windows tools may not follow them.
- Always run
findas a user with directory read permissions, or append2>/dev/null.
References
- [1] find(1) – Linux manual page (man7.org)
- [2] readlink(1) – Linux manual page (man7.org)
- [3] stat(1) – Linux manual page (man7.org)
All commands tested on WSL2 Ubuntu (24.04) with kernel 6.4+. Verified against official man-page documentation.