lrwxrwxrwx. 1 oracle oinstall 10 Oct 14 03:47 abc -> xyz
drwxr-xr-x. 6 oracle oinstall 4 Oct 26 21:11 xyz
i want to find that xyz is having a symbolic link with name abc
lrwxrwxrwx. 1 oracle oinstall 10 Oct 14 03:47 abc -> xyz
drwxr-xr-x. 6 oracle oinstall 4 Oct 26 21:11 xyz
i want to find that xyz is having a symbolic link with name abc
If you want to find all the links named abc
to a file xyz
are in current directory this could be done with:
find -L / -samefile `readlink -f xyz` -name abc
readlink -f xyz
can be replaced with a full path to a file (which it does in fact for the file in current directory).
If you know exact link name, but instead want to find just all the links to a file xyz
with any names, you could just omit name
like this:
find -L / -samefile `readlink -f xyz`
You can also add 2> /dev/null
at the end of the command to suppress "permission denied" warnings.
abc
. If he wants to find all links to the file xyz
, when the -name abc
part of the find command could be just omitted.
– NStorm
Jan 19 '22 at 21:00
There is no back reference or count of symbolic links maintained to a file or directory.
So, for example, it would be perfectly valid to delete the xyz directory. The presence of any symbolic links wouldn't prevent this, nor would it prevent the data in xyz from being destroyed. Any symbolic links would only be recognised as being invalid if an attempt was made to open them -- they would become "broken links".
The situation would be substantially different for hard links.
With zsh
:
print -rC1 - **/*(ND@e['[[ $REPLY -ef xyz ]]'])
Would print
r
aw on 1
C
olumn the files of type symlink (@
) with any name (*
), under and level of subdirectories (**/
), including hidden ones (D
), not complaining if there's no match (N
), and that are the same file as xyz
after symlink resolution (-ef
).
Note it would also report symlinks to another symlink or hardlink to xyz
.
If you just wanted to find symlinks whose target is the literal string xyz
, then it's just:
find . -lname xyz