4

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 !
yael
  • 2,363
  • 4
  • 28
  • 41
  • 1
    AFAIK there is no way to know if other files are symlinking to a file . ls -l under /tmp wouldn't work anyway, since symlinks could be placed to other dirs than /tmp . – Sandor Marton May 08 '13 at 17:04
  • Well there is a really ugly way. Scan the entire filesystem looking for links. I suspect you could work something out with `find`, `-type -l`, and `-lname`. – Zoredache May 08 '13 at 17:09

2 Answers2

4

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

USD Matt
  • 5,321
  • 14
  • 23
3

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

You can do like this:

find / -lname "filename"
cuonglm
  • 2,346
  • 2
  • 15
  • 20
  • the problem is if I need to check 100 files under / so it will take allot of time ............ – yael May 08 '13 at 17:39
  • @yael 100 files are checked very fast. Or did you mean 100 TB of files? – ott-- May 08 '13 at 18:20
  • @ott-- 100TB of files can checked very fast too if they're big files (of course if they're all 1B files you've got the opposite situation: Checking 100 trillion files would certainly take a long time :-) – voretaq7 May 08 '13 at 20:29