How to find all symbolic links ( symlinks ) to the target file / folder in Windows using only standard OS functions?

PS As a side question, you are also interested in how this problem can be solved in UNIX ?

The question, of course, is how to do this without resorting to third-party utilities (even if they are built-in, like mklink or ls ), as well as to sorting through all the files to see if they are not links.

2 answers 2

Just get all the symlinks from all sections, as stated here , then just check if they refer to this file / folder. The file itself does not know about the symlinks that refer to it. In WinAPI, this functionality is not provided, so this is the only option to do this.

UPDATE

As @ixSci wrote, in UNIX, things are similar to images

  • But after all, if I understand correctly, it is proposed to first analyze each file to determine if it is a symbolic link ... Is there any other way to get this list? - Artem Ionash
  • one
    @DukeSpont Chemical fs does not store their list anywhere - Flowneee
  • one
    In response, you can add that in UNIX, things are similar. - ixSci
  • @Flowneee and where, in this case, does the file store list of hard links that can be obtained from WinAPI through FindFirstFileName and FindNextFileName ? - Artyom Ionash
  • @DukeSpontaneous does not know exactly how it is done in NTFS, but most likely somewhere in the Master File Table. - Flowneee

As a side question, I am also interested in how this problem can be solved in UNIX?

as elsewhere: search.

in the posix-variant , as far as I know, no aids are provided for this.

In the variant for the gnu operating system, there is an option -samefile файл , which allows you to find hardlink and symlink-i (with the -L option).

An example to illustrate:

 $ mkdir test && cd test $ touch file other.file $ ln file file.hard $ ln -s file file.soft $ find . -samefile file ./file.hard ./file $ find -L . -samefile file ./file.hard ./file.soft ./file