Linux + how to identify if file is pointed by link/s

kshlinuxshell-scriptingsolaris

I create new file called – 192.9.200.1

    touch 192.9.200.1

then I create new link that will be pointed to 192.9.200.1 file

    ln -s 192.9.200.1 file

so finally I get:

     ls -ltr /tmp

    -rw-r--r--  1 root root        0 May  8 19:39 192.9.200.1
    lrwxrwxrwx  1 root root       11 May  8 19:39 file -> 192.9.200.1

but when I do ls -ltr on the 192.9.200.1 file I cant see if other link/s is point to 192.9.200.1

     ls -ltr 192.9.200.1
      -rw-r--r-- 1 root root 0 May  8 19:39 192.9.200.1

what the way to identify if file or directory have link/s ,

  • remark I don't want to do ls -ltr under /tmp directory to find links !

Best Answer

A symbolic link is similar to a shortcut in Windows. It's a entry in the file system that points to another file. The destination file is not touched and no change is made to the original files metadata - it does not know that it has been linked to.

You will not be able to tell if a file has symbolic links pointing at it just by looking at information from ls.

Hard links, however, increment the link count on the file system which can be seen in a directory listing. If you hard link two files to the same data, both will show a link count of 2