hard link unlinking

Discussion in 'macOS' started by pizzacake, Sep 11, 2008.

  1. pizzacake macrumors member

    Joined:
    Sep 13, 2006
    #1
    I'm running OS X Leopard 10.5.4 on an Intel iMac.

    In my user directory I create a text file called firstTextFile and list the directory's contents

    imac:~ me$ ls -l ~/
    -rw-r--r--@ 1 me staff 354 11 Sep 20:26 firstTextFile.rtf

    then I create a hard link to this firstTextFile

    imac:~ me$ ln /Users/me/firstTextFile.rtf secondTextFile.rtf

    then list directory contents

    imac:~ me$ ls -l ~/
    -rw-r--r--@ 2 me staff 354 11 Sep 20:26 firstTextFile.rtf
    -rw-r--r--@ 2 me staff 354 11 Sep 20:26 secondTextFile.rtf

    the 2 indicates they are hard linked (pointers) to the same data

    now I modify firstTextFile and save it

    then list directory contents

    imac:~ me$ ls -l ~/
    -rw-r--r--@ 1 me staff 363 11 Sep 20:31 firstTextFile.rtf
    -rw-r--r--@ 1 me staff 354 11 Sep 20:26 secondTextFile.rtf

    now the two files are unlinked separate files. I always thought if I open a hard link and modify it when I open the other hard links they also would be modified as all these hard links point to the same data. Anyone know what's going on?
     
  2. BobZune macrumors 6502a

    Joined:
    Oct 26, 2007
    Location:
    USA
    #2
    How you modify matters. Many editors delete and recreate the file, so the hard linking is lost (unlinked). Try a low level editor and see if that just modifies the file without deleting/creating-with-same-name.
     

Share This Page