symlink is great for identifying different characteristics of symbolic links. It will list if a symbolic link is broken (dangling), if it's absolute or relative and if it's pointing to another partition.
If you specify it, it will also remove broken/dangling symbolic links and/or change absolute links to relative ones.
First, we compile it:
OS X:
curl -O http://www.ibiblio.org/pub/Linux/utils/file/symlinks-1.4.tar.gz
tar xzf symlinks-1.4.tar.gz
cd symlinks-1.4/
export CFLAGS=-I/usr/include/malloc; make
If you want, you can install it by running make install
. In this case, I need it to be part of a script, so I will leave it in this folder for now.
If you run the binary without specifying anything, this is the output:
/V/M/t/symlink_test
😎 𝛌 ~/Downloads/symlinks-1.4/symlinks
symlinks: scan/change symbolic links - v1.3 - by Mark Lord
Usage: symlinks [-cdorstv] dirlist
Flags: -c == change absolute/messy links to relative
-d == delete dangling links
-o == warn about links across file systems
-r == recurse into subdirs
-s == shorten lengthy links (displayed in output only when -c not specified)
-t == show what would be done by -c
-v == verbose (show all symlinks)
Now, this is how it works:
I created 3 symbolic links:
- abc is broken. It references something that doesn't exist.
- ruben is linking to my
$HOME
directory in another partition. - tmp is linked to a folder in this partition.
This is how you can use the utility:
/V/M/t/symlink_test
😎 𝛌 pwd -P
/Volumes/MiniDrive/tmp/symlink_test
/V/M/t/symlink_test
😎 𝛌 ls -lhA
total 24
lrwxr-xr-x 1 ruben staff 4B Dec 14 08:27 abc -> /abc
lrwxr-xr-x 1 ruben staff 13B Dec 14 08:34 ruben -> /Users/ruben/
lrwxr-xr-x 1 ruben staff 23B Dec 14 08:35 tmp -> /Volumes/MiniDrive/tmp/
And this is the output you get without any parameters:
/V/M/t/symlink_test
😎 𝛌 ~/Downloads/symlinks-1.4/symlinks ./
dangling: /Volumes/MiniDrive/tmp/symlink_test/abc -> /abc
other_fs: /Volumes/MiniDrive/tmp/symlink_test/ruben -> /Users/ruben/
absolute: /Volumes/MiniDrive/tmp/symlink_test/tmp -> /Volumes/MiniDrive/tmp/
/V/M/t/symlink_test
😎 𝛌
You can easily redirect this to a file and grep/sort based on what you need to find.