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.
I think it’s easier the other way round, find all symlinks and grep the directory you want to move from results.
Something like ‘find /home/user -type -l -exec ls -l {} ; | grep yourdirectory’ and work from there. I don’t think there’s an easy way to list which symlinks point to any actual file.
You want
readlink -f
rather thanls -l
. OK, actually not exactly.readlink
won’t print path to the symlink so it’s not as straightforward.Also, you want
+
infind ... -exec ... +
rather than;
.