How do I (recursively) detect all symlinks in a directory that identify their target in an absolute as opposed to in a relative way?Since these links are very likely to break when an entire directory tree is moved I would like to have a way of identifying them.Even relative links may break if the directory tree is moved (if they happen to point outside the root of the directory tree), but I think this is addressed in this question.
Find all absolute links in a directory tree
symlink
To find absolute links, you can use find's -lname option if your find supports that (it's available at least in GNU find, on FreeBSD and macOS):find . -type l -lname '/*'This asks find to print the names of files which are symbolic links and whose content (target) matches /* using shell globbing.Strictly speaking, POSIX specifies that absolute pathnames start with one / or three or more /; to match that, you can usefind . -lname '/*' ! -lname '//*' -o -lname '///*'On what systems is //foo/bar different from /foo/bar? has more details on that.(Thanks to Sato Katsura for pointing out that -lname is GNU-specific, to fd0 for mentioning that it's actually also available on at least FreeBSD and macOS, and to Stphane Chazelas for bringing up the POSIX absolute pathname definition.)