How to find and list all the symbolic links created for a particular file?
Here is an example:
find -L /dir/to/start -xtype l -samefile ~/Pictures
or, maybe better:
find -L /dir/to/start -xtype l -samefile ~/Pictures 2>/dev/null
to get rid of some errors like Permission denied
, Too many levels of symbolic links
, or File system loop detected
which find
throws them when doesn't have the right permissions or other situations.
-L
- Follow symbolic links.-xtype l
- File is symbolic link-samefile name
- File refers to the same inode asname
. When-L
is in effect, this can include symbolic links.
Notes:
- Use lowercase L in
-xtype l
, not the digit 1. - On macOS / Darwin,
-xtype
is-type
.
Very simple, use option -lname
:
find / -lname /path/to/original/dir
From man find
:
-lname pattern
File is a symbolic link whose contents match shell pattern pattern. The
metacharacters do not treat `/' or `.' specially. If the -L option or the
-follow option is in effect, this test returns false unless the symbolic link
is broken.
Note: Remember that symbolic links could be anywhere, which includes a remote system (if you’re sharing files), so you may not be able to locate them all.