I want to move a directory with a bunch of subdirectories and files. But I have the feeling there might be some symlinks to a few of them elsewhere on the file system. (As in the directory contains the targets of symlinks.)

How do I search all files for symlinks pointing to them?

Some combination of find, stat, ls, realpath, readlink and maybe xargs? I can’t quite figure it out.

  • mina86@lemmy.wtf
    link
    fedilink
    English
    arrow-up
    1
    ·
    4 days ago

    You could pass $1 and $got through $(realpath -P -- ...) to make sure all the path are in canonical form. Though now that I’m thinking about it, stat is probably a better option anyway:

    want=/path/to/target/dir
    pattern=$(stat -c^%d:%i: -- "$want")
    find "$HOME" -type l -exec stat -Lc%d:%i:%n {} + | grep "$pattern"