link/symbolic link~ What is the difference?

William Lindley plug-discuss@lists.plug.phoenix.az.us
Wed, 18 Dec 2002 11:43:39 -0700 (MST)


Both types of link are quite unlike a copy.

    cp existing_file new_name

      creates a copy of existing_file called new_name.  The
      new file will have a unique inode, so changing the new
      file won't affect the old one, and vice versa.  NOTE: unlike
      DOS, unix "cp" by default stamps the new file with the current
      date and time; use "cp -p" to preserve the date and time.

    ln target_file new_name

      creates a directory entry called new_name which has the
      same inode (physical disk location) as the target_file.
      The target_file must be an existing file on the disk.
      Editing the file by either name changes them both.
      If you then delete (rm) one of them, the file contents
      stay on the disk... until you delete *all* of the inodes
      that point to it.

    ln -s target_file new_name

      creates a directory entry called new_name which is a
      reference (i.e., redirection) to the target_file.  The
      target_file need not even exist.  So "ln -s bar foo"
      just means that anytime you refer to "foo" it is the same
      as referring to "bar" ... if you delete the real file "bar"
      then "cat foo" will say "No such file or directory" even
      though the link "foo" exists (because "bar" doesn't).

\\/
http://www.wlindley.com